【问题标题】:smtp.SendMail cannot send mail to multiple recipent golangsmtp.SendMail 无法将邮件发送到多个recipent golang
【发布时间】:2015-09-02 20:13:52
【问题描述】:

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

代码:

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

我做错了什么?

【问题讨论】:

  • this 答案可能有用。

标签: email go sendmail


【解决方案1】:

您的代码 sn-p 不完整,与您的电子邮件不匹配。可以发更多代码吗?

无论如何你可以尝试替换:

[]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)
    }
}

【讨论】:

  • 这有帮助。 :) 谢谢。我会试试你的包裹。 :)
猜你喜欢
  • 1970-01-01
  • 2019-06-19
  • 1970-01-01
  • 2016-08-21
  • 2015-09-05
  • 1970-01-01
  • 1970-01-01
  • 2018-08-15
  • 2020-04-14
相关资源
最近更新 更多