英文:
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
你做错了什么?
英文:
I want to send mail to multiple recipients in Go, with my yahoo mail, but I from all recipients only I get mail.
Code:
err := smtp.SendMail(
"smtp.mail.yahoo.com:25",
auth,
"testmail1@yahoo.com",
[]string{"testmail1@yahoo.com, testmail2@yahoo.com"},
[]byte("test")
message:
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
This is output:
2015/05/18 20:22:26 501 Syntax error in arguments
What have I done wrong?
答案1
得分: 2
你的代码片段不完整,与你的电子邮件不匹配。你能发送更多的代码吗?
无论如何,你可以尝试替换:
[]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)
}
}
英文:
Your code snippet is incomplete and does not match your email. Could you send more code?
Anyway you can try replacing:
[]string{"testmail1@yahoo.com, testmail2@yahoo.com"},
By:
[]string{"testmail1@yahoo.com", "testmail2@yahoo.com"},
Also you can try my package Gomail to easily send emails:
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)
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论