golang 发送多人邮件 textproto.Error{Code:554, Msg:"Transaction failed: Illegal semicolon, not in group"


网上很多版本发送邮件都是用; 号,关键在于,多个邮件分割不能用; 号,需要用,号

 

// send mail
func SendMail(subject string, message string, from *mail.Address, to []string, smtpConfig SmtpConfig, isHtml bool) error {
    auth := smtp.PlainAuth(
        "",
        smtpConfig.Username,
        smtpConfig.Password,
        smtpConfig.Host,
    )
    contentType := "text/plain"
    if isHtml {
        contentType = "text/html"
    }
    msg := fmt.Sprintf("To: %s\r\nFrom: %s\r\nSubject: %s\r\nContent-Type: %s; charset=UTF-8\r\n\r\n%s",
        strings.Join(to, ","), from.String(), subject, contentType, message)
    return smtp.SendMail(smtpConfig.Addr, auth, from.Address, to, []byte(msg))
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM