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

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!

  • 写回答

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?