https://github.com/windvalley/go-mailparser
Go lib for parsing email in simple way.
https://github.com/windvalley/go-mailparser
email email-parser go-mailparser parse-email
Last synced: 3 months ago
JSON representation
Go lib for parsing email in simple way.
- Host: GitHub
- URL: https://github.com/windvalley/go-mailparser
- Owner: windvalley
- License: mit
- Created: 2023-06-30T04:24:18.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-07-03T08:12:46.000Z (almost 2 years ago)
- Last Synced: 2025-01-14T12:50:20.049Z (5 months ago)
- Topics: email, email-parser, go-mailparser, parse-email
- Language: Go
- Homepage:
- Size: 21.5 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# go-mailparser
Go lib for parsing email in simple way.
## Features
- Support parsing emails with content types of `text/*` and `multipart/*`.
- Support parsing Chinese content, such as Chinese characters in email address aliases, email subject, and email content.
- Support parsing email attachments.
- Support parsing emails with content encoded in base64.
- Support parsing email headers and email content separately, or parse them all at once.## Examle
```go
package mainimport (
"fmt"
"log"
"strings""github.com/bytbox/go-pop3"
"github.com/windvalley/go-mailparser"
)func main() {
c, err := pop3.Dial("mail.xxx.com:110")
if err != nil {
log.Fatal(err)
}
defer func() {
if err := c.Quit(); err != nil {
fmt.Println(err)
}
}()if err := c.Auth("[email protected]", "yourpassword"); err != nil {
log.Fatal(err)
}msgs, _, err := c.ListAll()
if err != nil {
log.Fatal(err)
}for _, v := range msgs {
msg, err := c.Retr(v)
if err != nil {
fmt.Println(err)
continue
}// string to io.Reader
msgReader := strings.NewReader(msg)// parse email
res, err := mailparser.Parse(msgReader)
if err != nil {
fmt.Println(err)
continue
}// check MailMessage
fmt.Printf("result: %+v\n", res)// check attachments
for _, v := range res.Attachments {
// You can handle the file data (v.Data) appropriately based on the content type.
fmt.Printf("filename: %s, content-type: %s\n", v.Filename, v.ContentType)
}
}
}
```## License
This project is under the MIT License.
See the [LICENSE](LICENSE) file for the full license text.