您需要将From
邮件字段设置为Sandy Sender <sender@example.com>
:
...
From: Sandy Sender <sender@example.com>
To: recipient@example.com
Subject: Hello!
This is the body of the message.
并且只使用地址 ( sender@example.com
) Client.Mail
。
或者,您可以使用我的包Gomail:
package main
import (
"gopkg.in/gomail.v2"
)
func main() {
m := gomail.NewMessage()
m.SetAddressHeader("From", "sender@example.com", "Sandy Sender")
m.SetAddressHeader("To", "recipient@example.com")
m.SetHeader("Subject", "Hello!")
m.SetBody("text/plain", "This is the body of the message.")
d := gomail.NewPlainDialer("smtp.example.com", 587, "user", "123456")
if err := d.DialAndSend(m); err != nil {
panic(err)
}
}