duanqu9292
2016-06-17 15:51
浏览 68
已采纳

GoLang net / smtp sendMail发送给带有加号的收件人

I am writing a registration form using GoLang 1.5. I have it all working, but I've noticed if I attempt to sign up using an e-mail with a plus sign in it (someemail+theirlabel@theirdomain.com) I receive the following error:

Transaction failed: Illegal semicolon, not in group

Googling for this hasn't yielded much results, and it seems like Go should handle the plus sign just fine.

import (
  "net/smtp"
  "net/mail"
)

func sendEmail(t *Email) bool {
    to := []string{"johndoe+test@gmail.com"}
    err = smtp.SendMail(smtp_url, auth, from_email, to, buff.Bytes())
    if err != nil {
        log.Fatal(err)
        // outputs: Transaction failed: Illegal semicolon, not in group
    }
}

I appreciate any advice I get on this.

Thanks!

图片转代码服务由CSDN问答提供 功能建议

我正在使用GoLang 1.5编写注册表。 我都能正常使用,但是我注意到,如果我尝试使用带有加号的电子邮件进行注册(someemail+theirlabel@theirdomain.com),则会收到以下错误消息: \ n

交易失败:非法分号,不在组中

对此进行谷歌搜索并没有产生太多结果,而且看起来Go应该可以很好地处理加号了。

  import(
“ net / smtp” 
“ net / mail” 
)
 
func sendEmail(t * Email)bool {
至:= []字符串 {“ johndoe+test@gmail.com”} 
 err = smtp.SendMail(smtp_url,auth,from_email,to,buff.Bytes())
 if err!= nil {
 log.Fatal(err)\  n //输出:事务失败:非法分号,不在组中
} 
} 
   
 
 

对此,我很感谢。

谢谢!

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanlu1908 2016-06-19 02:02
    已采纳

    I was able to reproduce this error if and only if I had a semi-colon in the To header within the message body. E.g.:

    msg := []byte("To: email1@example.com;email2@example.com
    Subject: foo
    
    body
    ")
    

    Double-check the To header you're sending and make sure it uses commas instead of semi-colons to separate multiple recipients.

    打赏 评论

相关推荐 更多相似问题