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

标签 email go sendmail

我想使用我的 yahoo 邮件向 Go 中的多个收件人发送邮件,但我只能从所有收件人处收到邮件。

代码:

err := smtp.SendMail(
    "smtp.mail.yahoo.com:25",
    auth,
    "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a7d3c2d4d3cac6cecb96e7dec6cfc8c889c4c8ca" rel="noreferrer noopener nofollow">[email protected]</a>",
    []string{"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="aedacbdddac3cfc7c29feed7cfc6c1c180cdc1c3" rel="noreferrer noopener nofollow">[email protected]</a>, <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4d39283e39202c24217f0d342c252222632e2220" rel="noreferrer noopener nofollow">[email protected]</a>"},
    []byte("test")

消息:

From: "testMail1" <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a5d1c0d6d1c8c4ccc994e5dcc4cdcaca8bc6cac8" rel="noreferrer noopener nofollow">[email protected]</a>>
To: testMail1 <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5b2f3e282f363a32376a1b223a33343475383436" rel="noreferrer noopener nofollow">[email protected]</a>>, testMail2 <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6b1f0e181f060a0207592b120a03040445080406" rel="noreferrer noopener nofollow">[email protected]</a>>,
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{"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="91e5f4e2e5fcf0f8fda0d1e8f0f9fefebff2fefc" rel="noreferrer noopener nofollow">[email protected]</a>, <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8afeeff9fee7ebe3e6b8caf3ebe2e5e5a4e9e5e7" rel="noreferrer noopener nofollow">[email protected]</a>"},

作者:

[]string{"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="86f2e3f5f2ebe7efeab7c6ffe7eee9e9a8e5e9eb" rel="noreferrer noopener nofollow">[email protected]</a>", "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fd89988e89909c9491cfbd849c959292d39e9290" rel="noreferrer noopener nofollow">[email protected]</a>"},

你也可以试试我的套餐Gomail轻松发送电子邮件:

package main

import (
    "gopkg.in/gomail.v2"
)

func main() {
    m := gomail.NewMessage()
    m.SetAddressHeader("From", "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7a0e1f090e171b13164b3a031b12151554191517" rel="noreferrer noopener nofollow">[email protected]</a>", "testMail1")
    m.SetHeader("To",
        m.FormatAddress("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4f3b2a3c3b222e26237e0f362e272020612c2022" rel="noreferrer noopener nofollow">[email protected]</a>", "testMail1"),
        m.FormatAddress("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6e1a0b1d1a030f07025c2e170f060101400d0103" rel="noreferrer noopener nofollow">[email protected]</a>", "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)
    }
}

关于email - smtp.SendMail无法向多个recipent golang发送邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30310646/

相关文章:

linux - 如何安装和配置邮件服务器 debian

ruby-on-rails - sendmail:OpenSSL::SSL::SSLError:主机名不匹配

sendmail - 我如何链接 digitalocean、namecheap 和发送网格来发送邮件,这是我当前的域名和 DNS 配置

email - 使用 luasocket smtp 和 ssl 发送电子邮件

java - 使用 API 从 Java 发送电子邮件,而不是使用 localhost

email - 戈兰 : How to UTF8 both subject header and body in email?

json - 从 golang 中的 json 文件中读取 slice

email - TFS:电子邮件差异

go - 在编译时解析模板

profiling - Go 分析器的输出令人困惑(而且不正确?)