smtp.SendMail 无法将邮件发送给多个 recipent golang
smtp.SendMail cannot send mail to multiple recipent golang
我想用我的雅虎邮箱向 Go 中的多个收件人发送邮件,但我只从所有收件人那里收到邮件。
代码:
err := smtp.SendMail(
"smtp.mail.yahoo.com:25",
auth,
"testmail1@yahoo.com",
[]string{"testmail1@yahoo.com, testmail2@yahoo.com"},
[]byte("test")
留言:
From: "testMail1" <testmail1@yahoo.com>
To: testMail1 <testmail1@yahoo.com>, testMail2 <testmail2@yahoo.com>,
Subject: "mail"
MIME-Version: 1.0
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: base64
这是输出:
2015/05/18 20:22:26 501 Syntax error in arguments
我做错了什么?
您的代码片段不完整,与您的电子邮件不匹配。你能发送更多代码吗?
无论如何你可以尝试替换:
[]string{"testmail1@yahoo.com, testmail2@yahoo.com"},
作者:
[]string{"testmail1@yahoo.com", "testmail2@yahoo.com"},
您也可以试试我的包 Gomail 来轻松发送电子邮件:
package main
import (
"gopkg.in/gomail.v2"
)
func main() {
m := gomail.NewMessage()
m.SetAddressHeader("From", "testmail1@yahoo.com", "testMail1")
m.SetHeader("To",
m.FormatAddress("testmail1@yahoo.com", "testMail1"),
m.FormatAddress("testmail2@yahoo.com", "testMail2"),
)
m.SetHeader("Subject", "mail")
m.SetBody("text/plain", "Hello!")
d := gomail.NewPlainDialer("smtp.mail.yahoo.com", 25, "login", "password")
if err := d.DialAndSend(m); err != nil {
panic(err)
}
}
我想用我的雅虎邮箱向 Go 中的多个收件人发送邮件,但我只从所有收件人那里收到邮件。
代码:
err := smtp.SendMail(
"smtp.mail.yahoo.com:25",
auth,
"testmail1@yahoo.com",
[]string{"testmail1@yahoo.com, testmail2@yahoo.com"},
[]byte("test")
留言:
From: "testMail1" <testmail1@yahoo.com>
To: testMail1 <testmail1@yahoo.com>, testMail2 <testmail2@yahoo.com>,
Subject: "mail"
MIME-Version: 1.0
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: base64
这是输出:
2015/05/18 20:22:26 501 Syntax error in arguments
我做错了什么?
您的代码片段不完整,与您的电子邮件不匹配。你能发送更多代码吗?
无论如何你可以尝试替换:
[]string{"testmail1@yahoo.com, testmail2@yahoo.com"},
作者:
[]string{"testmail1@yahoo.com", "testmail2@yahoo.com"},
您也可以试试我的包 Gomail 来轻松发送电子邮件:
package main
import (
"gopkg.in/gomail.v2"
)
func main() {
m := gomail.NewMessage()
m.SetAddressHeader("From", "testmail1@yahoo.com", "testMail1")
m.SetHeader("To",
m.FormatAddress("testmail1@yahoo.com", "testMail1"),
m.FormatAddress("testmail2@yahoo.com", "testMail2"),
)
m.SetHeader("Subject", "mail")
m.SetBody("text/plain", "Hello!")
d := gomail.NewPlainDialer("smtp.mail.yahoo.com", 25, "login", "password")
if err := d.DialAndSend(m); err != nil {
panic(err)
}
}