我正在golang上通过smtp发送电子邮件,效果很好。要设置电子邮件的发件人,我使用Client.Mail功能:
func (c *Client) Mail(from string) error
收件人收到电子邮件后,他将发件人视为明文电子邮件地址: [email protected]
我希望发件人显示为:Sandy Sender <[email protected]>
。
这可能吗?我尝试将发件人设置为Sandy Sender <[email protected]>
或仅设置为发件人,Sandy Sender
但都无法正常工作。我得到了错误501 5.1.7 Invalid address
您需要将From
邮件的字段设置为Sandy Sender <[email protected]>
:
...
From: Sandy Sender <[email protected]>
To: [email protected]
Subject: Hello!
This is the body of the message.
并仅使用中的地址([email protected]
)Client.Mail
。
或者,您可以使用我的软件包Gomail:
package main
import (
"gopkg.in/gomail.v2"
)
func main() {
m := gomail.NewMessage()
m.SetAddressHeader("From", "[email protected]", "Sandy Sender")
m.SetAddressHeader("To", "[email protected]")
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)
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句