Advertisement
arxeiss

Email sending

May 16th, 2016
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.90 KB | None | 0 0
  1. func sendmail(template *data.Template, attachments []*data.Attachment, recipient *data.Recipient, sender *data.Sender) error {
  2.     m := gomail.NewMessage()
  3.     m.SetHeader("From", m.FormatAddress(sender.Email, sender.GetFullName()))
  4.     m.SetHeader("To", m.FormatAddress(recipient.Email, recipient.GetFullName()))
  5.     m.SetHeader("Subject", template.Subject)
  6.     for i := range attachments {
  7.         m.Embed(mailer.WWW_Root+"/images/uploads/"+attachments[i].FileName, gomail.Rename(attachments[i].Name))
  8.     }
  9.     content, err := ParseTemplate(template, attachments, recipient, sender, true)
  10.     if err != nil {
  11.         return err
  12.     }
  13.     if template.Type == data.TYPE_HTML {
  14.         m.SetBody("text/html", content)
  15.     } else {
  16.         m.SetBody("text/plain", content)
  17.     }
  18.  
  19.     d := gomail.NewDialer(mailer.SMTP, mailer.Port, mailer.SMTPLogin, mailer.SMTPPassword)
  20.     d.TLSConfig = &tls.Config{InsecureSkipVerify: mailer.SkipInsecureTLS}
  21.     return d.DialAndSend(m)
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement