123456789101112131415161718192021222324252627282930313233343536 |
- package utils
- import (
- "net/smtp"
- )
- // Mail define mail struct
- type Mail struct {
- ToName string
- ToAddr string
- FromName string
- FromAddr string
- Subject string
- Body string
- }
- //Send send mail to recipients
- func (m *Mail) Send() error {
- config := GetConfig()
- mime := "\nMIME-version: 1.0;\nContent-Type: text/html; charset=\"UTF-8\";\n\n"
- msg := []byte("From: " + m.FromName + " <" + m.FromAddr + ">" + "\r\n" +
- "To: " + m.ToAddr + "\r\n" +
- "Subject: " + m.Subject + mime + "\r\n\r\n" +
- m.Body + "\r\n")
- auth := smtp.PlainAuth("", config.SMTP.User, config.SMTP.Password, config.SMTP.Host)
- err := smtp.SendMail(config.SMTP.Host+":"+config.SMTP.Port, auth, m.FromAddr, []string{m.ToAddr}, msg)
- return err
- }
|