smtp.SendMail无法向多个recipent golang发送邮件

时间:2015-05-18 18:41:57

标签: email go sendmail

我想通过我的雅虎邮件向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

我做错了什么?

1 个答案:

答案 0 :(得分: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)
    }
}