golang    2016-05-28 15:19:05    62    0    0

1. Mail Configuration

When we have certificates for our SMTP servers, the TLSSkipVerify should be set to true. Otherwise, set to false

  1. // MailConfig contains all configuration for mail
  2. type MailConfig struct {
  3. AuthMailAddr string
  4. AuthPassword string
  5. SendFrom string
  6. SMTPHost string
  7. TLSSkipVerify bool
  8. }
  9. var config MailConfig
  10. func SendMail(mailto string, subject string, body string) error {
  11. // Code
  12. }

2. Set From and To

  1. from := mail.Address{
  2. Name: "",
  3. Address: config.SendFrom,
  4. }
  5. to := mail.Address{
  6. Name: "",
  7. Address: mailto,
  8. }

3. Setup Header and Message

  1. // Setup headers
  2. headers := make(map[string]string)
  3. headers["From"] = from.String()
  4. headers["To"] = to.String()
  5. headers["Subject"] = subject
  6. // Setup message
  7. message := ""
  8. for k, v := range headers {
  9. message += fmt.Sprintf("%s: %s\r\n", k, v)
  10. }
  11. message += "