登录
首页 >  Golang >  Go问答

如何使用 amazon smtp 通过端口 587 发送电子邮件

来源:stackoverflow

时间:2024-04-03 08:12:36 315浏览 收藏

小伙伴们有没有觉得学习Golang很有意思?有意思就对了!今天就给大家带来《如何使用 amazon smtp 通过端口 587 发送电子邮件》,以下内容将会涉及到,若是在学习中对其中部分知识点有疑问,或许看了本文就能帮到你!

问题内容

我想使用 Amazon SMTP 发送电子邮件。

我正在使用示例

https://gist.github.com/jim3ma/b5c9edeac77ac92157f8f8affa290f45

但不起作用!

我收到此消息错误:

tls:第一个记录看起来不像 TLS 握手 恐慌:tls:第一条记录看起来不像 TLS 握手


解决方案


尝试使用https://golang.org/pkg/net/smtp/#example_SendMail中的代码

package main

import (
    "log"
    "net/smtp"
)

func main() {
    // Set up authentication information.
    auth := smtp.PlainAuth("", "<a target='_blank'  href='https://www.17golang.com/gourl/?redirect=MDAwMDAwMDAwML57hpSHp6VpkrqbYLx2eayza4KafaOkbLS3zqSBrJvPsa5_0Ia6sWuR4Juaq6t9nq6ycZqKgG2svpXKqIBkrtu-i2LMmbrbrZuueqbGeYaeyYCkppKihqKu3LOijnmMlbN4cpSSt89pkqp5qLBkep6yo6Nkf42hpLLdyqKBrIXRsot-lpHdz3Y' rel='nofollow'>[email protected]</a>", "password", "mail.example.com")

    // Connect to the server, authenticate, set the sender and recipient,
    // and send the email all in one step.
    to := []string{"<a target='_blank'  href='https://www.17golang.com/gourl/?redirect=MDAwMDAwMDAwML57hpSHp6VpkrqbYLx2eayza4KafaOkbLS3zqSBrJvPsa5_0Ia6sWuR4Juaq6t9nq6ycZqKgG2svpXKqIBkrtu-i2LMmbrbrZuueqbGeYaeyYCkppKihqKu3LOijnmMlbN4cpSSt89pkqp5qLBkep6yo6Nkf42hpLLdyqKBrIXRsot-lpHdz3Y' rel='nofollow'>[email protected]</a>"}
    msg := []byte("To: <a target='_blank'  href='https://www.17golang.com/gourl/?redirect=MDAwMDAwMDAwML57hpSHp6VpkrqbYLx2eayza4KafaOkbLS3zqSBrJvPsa5_0Ia6sWuR4Juaq6t9nq6ycZqKgG2svpXKqIBkrtu-i2LMmbrbrZuueqbGeYaeyYCkppKihqKu3LOijnmMlbN4cpSSt89pkqp5qLBkep6yo6Nkf42hpLLdyqKBrIXRsot-lpHdz3Y' rel='nofollow'>[email protected]</a>\r\n" +
        "Subject: discount Gophers!\r\n" +
        "\r\n" +
        "This is the email body.\r\n")
    err := smtp.SendMail("mail.example.com:25", auth, "<a target='_blank'  href='https://www.17golang.com/gourl/?redirect=MDAwMDAwMDAwML57hpSHp6VpkrqbYLx2eayza4KafaOkbLS3zqSBrJvPsa5_0Ia6sWuR4Juaq6t9nq6ycZqKgG2svpXKqIBkrtu-i2LMmbrbrZuueqbGeYaeyYCkppKihqKu3LOijnmMlbN4cpSSt89pkqp5qLBkep6yo6Nkf42hpLLdyqKBrIXRsot-lpHdz3Y' rel='nofollow'>[email protected]</a>", to, msg)
    if err != nil {
        log.Fatal(err)
    }
}

终于介绍完啦!小伙伴们,这篇关于《如何使用 amazon smtp 通过端口 587 发送电子邮件》的介绍应该让你收获多多了吧!欢迎大家收藏或分享给更多需要学习的朋友吧~golang学习网公众号也会发布Golang相关知识,快来关注吧!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>