Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/knadh/go-pop3
A simple Go POP3 client library for connecting and reading mails from POP3 servers.
https://github.com/knadh/go-pop3
email-client mail pop pop3 pop3-client pop3-protocol
Last synced: about 2 months ago
JSON representation
A simple Go POP3 client library for connecting and reading mails from POP3 servers.
- Host: GitHub
- URL: https://github.com/knadh/go-pop3
- Owner: knadh
- License: mit
- Created: 2021-06-27T14:41:55.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-02-27T10:41:56.000Z (10 months ago)
- Last Synced: 2024-06-18T18:42:56.174Z (6 months ago)
- Topics: email-client, mail, pop, pop3, pop3-client, pop3-protocol
- Language: Go
- Homepage:
- Size: 12.7 KB
- Stars: 75
- Watchers: 5
- Forks: 23
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-pop3
A simple Go POP3 client library for connecting and reading mails from POP3 servers. This is a full rewrite of [TheCreeper/go-pop3](https://github.com/TheCreeper/go-pop3) with bug fixes and new features.
## Install
`go get -u github.com/knadh/go-pop3`## Example
```go
import (
"fmt"
"github.com/knadh/go-pop3"
)func main() {
// Initialize the client.
p := pop3.New(pop3.Opt{
Host: "pop.gmail.com",
Port: 995,
TLSEnabled: true,
})// Create a new connection. POP3 connections are stateful and should end
// with a Quit() once the opreations are done.
c, err := p.NewConn()
if err != nil {
log.Fatal(err)
}
defer c.Quit()// Authenticate.
if err := c.Auth("myuser", "mypassword"); err != nil {
log.Fatal(err)
}// Print the total number of messages and their size.
count, size, _ := c.Stat()
fmt.Println("total messages=", count, "size=", size)// Pull the list of all message IDs and their sizes.
msgs, _ := c.List(0)
for _, m := range msgs {
fmt.Println("id=", m.ID, "size=", m.Size)
}// Pull all messages on the server. Message IDs go from 1 to N.
for id := 1; id <= count; id++ {
m, _ := c.Retr(id)fmt.Println(id, "=", m.Header.Get("subject"))
// To read the multi-part e-mail bodies, see:
// https://github.com/emersion/go-message/blob/master/example_test.go#L12
}// Delete all the messages. Server only executes deletions after a successful Quit()
for id := 1; id <= count; id++ {
c.Dele(id)
}
}
```[![PkgGoDev](https://pkg.go.dev/badge/github.com/knadh/go-pop3)](https://pkg.go.dev/github.com/knadh/go-pop3)
### To-do: tests
Setup a Docker test environment that runs [InBucket](https://github.com/inbucket/inbucket) POP3 + SMTP server to run a dummy POP3 server and test all the commands in the lib.Licensed under the MIT License.