https://github.com/koddr/go-email-sender
📮 Simple (but useful) email sender written in pure Go v1.17. Support HTML templates and attachments.
https://github.com/koddr/go-email-sender
email email-sender email-template go golang smtp smtp-protocol
Last synced: 5 months ago
JSON representation
📮 Simple (but useful) email sender written in pure Go v1.17. Support HTML templates and attachments.
- Host: GitHub
- URL: https://github.com/koddr/go-email-sender
- Owner: koddr
- License: apache-2.0
- Created: 2021-08-30T11:38:46.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-02-08T11:56:26.000Z (over 2 years ago)
- Last Synced: 2025-04-29T19:58:59.787Z (5 months ago)
- Topics: email, email-sender, email-template, go, golang, smtp, smtp-protocol
- Language: Go
- Homepage: https://pkg.go.dev/github.com/koddr/go-email-sender
- Size: 27.3 KB
- Stars: 8
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 📮 Go Email Sender
[](https://pkg.go.dev/github.com/koddr/go-email-sender)
Simple (but useful) email sender written in pure Go `v1.17`. Yes, _yet another_ email package here! 😅
Support **HTML templates** and **attachments**.
## Send HTML email
Method signature:
```go
func (s *Sender) SendHTMLEmail(
templatePath string,
to []string,
cc []string,
subject string,
data interface{},
files []string,
) error
```Example:
```go
// Create a new struct for the email data.
type HTMLEmailData struct {
Name string
Website string
}// Create a new SMTP sender instance with your auth params.
sender := NewEmailSender("mail@test.com", "secret", "smtp.test.com", 25)// Send the email with an HTML template.
if err := sender.SendHTMLEmail(
"my/templates/welcome.html", // path to the HTML template
[]string{
"mail@example.com", // slice of emails to send
},
[]string{
"copy-mail@example.com", // slice of emails to send message copy
},
"It's a test email!", // subject of the email
&HTMLEmailData{
Name: "Vic",
Website: "https://shostak.dev/",
},
[]string{
"my/files/image.jpg", // slice of files to send
},
); err != nil {
// Throw error message, if something went wrong.
return fmt.Errorf("Something went wrong: %v", err)
}
```## Send plain text email
Method signature:
```go
func (s *Sender) SendPlainEmail(
to []string,
cc []string,
subject string,
data interface{},
files []string,
) error
```Example:
```go
// Create a new SMTP sender instance with your auth params.
sender := NewEmailSender("mail@test.com", "secret", "smtp.test.com", 25)// Send the email with a plain text.
if err := sender.SendPlainEmail(
[]string{
"mail@example.com", // slice of emails to send
},
[]string{
"copy-mail@example.com", // slice of emails to send message copy
},
"It's a test email!", // subject of the email
"Here is a plain text body.", // body of the email
[]string{
"my/files/image.jpg", // slice of files to send
},
); err != nil {
// Throw error message, if something went wrong.
return fmt.Errorf("Something went wrong: %v", err)
}
```## ⚠️ License
Apache-2.0 © [Vic Shóstak](https://github.com/koddr) & [True web artisans](https://truewebartisans.com).