Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tls smtp support #68

Merged
merged 2 commits into from
Oct 3, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add reply-to
  • Loading branch information
chester committed Oct 3, 2018
commit 08fcdc57582dd19a6fa1baf8585fca840624b70e
10 changes: 7 additions & 3 deletions email.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var ErrMissingContentType = errors.New("No Content-Type found for MIME entity")

// Email is the type used for email messages
type Email struct {
ReplyTo []string
From string
To []string
Bcc []string
Expand Down Expand Up @@ -251,13 +252,16 @@ func (e *Email) AttachFile(filename string) (a *Attachment, err error) {
func (e *Email) msgHeaders() (textproto.MIMEHeader, error) {
res := make(textproto.MIMEHeader, len(e.Headers)+4)
if e.Headers != nil {
for _, h := range []string{"To", "Cc", "From", "Subject", "Date", "Message-Id", "MIME-Version"} {
for _, h := range []string{"Reply-To", "To", "Cc", "From", "Subject", "Date", "Message-Id", "MIME-Version"} {
if v, ok := e.Headers[h]; ok {
res[h] = v
}
}
}
// Set headers if there are values.
if _, ok := res["Reply-To"]; !ok && len(e.ReplyTo) > 0 {
res.Set("Reply-To", strings.Join(e.ReplyTo, ", "))
}
if _, ok := res["To"]; !ok && len(e.To) > 0 {
res.Set("To", strings.Join(e.To, ", "))
}
Expand Down Expand Up @@ -468,12 +472,12 @@ func (e *Email) SendWithTLS(addr string, a smtp.Auth, t *tls.Config) error {
if err != nil {
return err
}

conn, err := tls.Dial("tcp", addr, t)
if err != nil {
return err
}

c, err := smtp.NewClient(conn, t.ServerName)
if err != nil {
return err
Expand Down