dongzhijing8202 2014-11-09 10:09
浏览 51

在localhost smtp上发送邮件不起作用

I am trying to send an email to the localhost stmp server. I am using fakesmtp program to receive email from localhost.

Look at following code snippet

package mail

import (
    "encoding/base64"
    "fmt"
    "log"
    "net/mail"
    "net/smtp"
    "strings"
)

func encodeRFC2047(String string) string {
    // use mail's rfc2047 to encode any string
    addr := mail.Address{String, ""}
    return strings.Trim(addr.String(), " <>")
}

func Send() {
    // Set up authentication information.

    smtpServer := "127.0.0.1:2525"
    auth := smtp.PlainAuth(
        "",
        "admin",
        "admin",
        smtpServer,
    )

    from := mail.Address{"example", "info@example.com"}
    to := mail.Address{"customer", "customer@example.com"}
    title := "Mail"

    body := "This is an email confirmation."

    header := make(map[string]string)
    header["From"] = from.String()
    header["To"] = to.String()
    header["Subject"] = encodeRFC2047(title)
    header["MIME-Version"] = "1.0"
    header["Content-Type"] = "text/plain; charset=\"utf-8\""
    header["Content-Transfer-Encoding"] = "base64"

    message := ""
    for k, v := range header {
        message += fmt.Sprintf("%s: %s
", k, v)
    }
    message += "
" + base64.StdEncoding.EncodeToString([]byte(body))

    // Connect to the server, authenticate, set the sender and recipient,
    // and send the email all in one step.
    err := smtp.SendMail(
        smtpServer,
        auth,
        from.Address,
        []string{to.Address},
        []byte(message),
        //[]byte("This is the email body."),
    )
    if err != nil {
        log.Fatal(err)
    }
}

When I executed the send function, I've got the error unencrypted connection. Why?

  • 写回答

1条回答 默认 最新

  • duan205571 2014-11-09 16:20
    关注

    Most likely the server does not allow you to use plain-text authentication over an unencrypted connection, which is a sensible default for almost any MTA out there. Either change authentication info to e.g. digest, or enable SSL/TLS in you client code.

    Remember to use tcpdump or wireshark to check what is actually transmitted.

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图