2019-07-16 18:28
浏览 1.5k


I am using go-smtp to attempt to send an email to myself: https://github.com/emersion/go-smtp

    auth := sasl.NewPlainClient("", USERNAME, PASSWORD)
    to := []string{USERNAME}

    msg := strings.NewReader("To: " + USERNAME + "
" +
        "Subject: testing golang go-smtp!
" +
" +
        "This is the email body.

    err := smtp.SendMail(SERVER_HOST + ":" + SERVER_PORT, auth, USERNAME, to, msg)
    if err != nil {

The output is: EOF exit status 1

I am connecting to smtp.gmail.com:465 and can send email through thunderbird okay.

Thanks for your help.


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

我正在使用go-smtp尝试向自己发送电子邮件: https://github.com/emersion/go-smtp

   auth:= sasl.NewPlainClient(“”,USERNAME,PASSWORD)
到:= [] string {USERNAME} 
 msg:= strings.NewReader(“ To:” + USERNAME +“ 
” +  
“主题:测试golang go-smtp!
” + 
” + 
错误:= smtp。  Sender(SERVER_HOST +“:” + SERVER_PORT,auth,USERNAME,to,msg)
如果err!= nil {
 \  n 

输出为: EOF exit状态1




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

1条回答 默认 最新

  • dongshushi5579 2019-07-17 12:56

    Check out the "Configuration options" section here https://support.google.com/a/answer/176600?hl=en. It mentions that Gmail uses SSL for the SMTP server on port 465 and TLS for port 587. To resolve your issue, you could use port 587 because the smtp.SendMail() function internally makes a call to net.Dial() that uses plain TCP to send the mail traffic with a call to STARTTLS later in the process.

    If you want to use port 465, here is a nice example that works for sending emails using SSL.


    The main difference between the two methods as also mentioned in the above link is that in SSL, the TLS connection is established from the beginning whereas if you used port 587, the connection starts over plain TCP without encryption.

    点赞 评论

相关推荐 更多相似问题