dpi10335 2019-07-16 18:28
浏览 3005
已采纳

go-smtp,无法通过gmail发送电子邮件,获得EOF

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 {
        log.Fatal(err)
    }

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.

Walter

  • 写回答

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.

    https://gist.github.com/chrisgillis/10888032

    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.

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

    报告相同问题?

    悬赏问题

    • ¥30 AXI VIP验证多余打印问题
    • ¥15 利用加权最小二乘法求某品牌手机价格指标,已按照总销量计算出权重,各类型号手机价格已知,如何求得价格指标?
    • ¥15 如何自制一个硬件钱包,有兴趣的朋友一起交流
    • ¥15 (关键词-聊天软件)
    • ¥15 求大家看看这个编程的编法没有思路啊
    • ¥20 WSL打开图形化程序子窗口无法点击
    • ¥15 Jupyter Notebook 数学公式不渲染
    • ¥20 ERR_CACHE_MISS 确认重新提交表单
    • ¥20 关于vba使用HTMLfile执行js函数问题
    • ¥60 悬赏求解,通过实时现场摄像头的视频图像识别其他对家打出的麻将牌,识别麻将牌,识别牌墙位置,通过识别对家打出了什么牌