doushi8187 2015-07-14 19:23
浏览 53

收据地址不会显示在golang smtp客户端发送的电子邮件中

Here is the code snippet to send the email via a local postfix server:

from := r.FormValue("from")
to := strings.Split(r.FormValue("to"), ";")
body := r.FormValue("body")
mime := "MIME-version:1.0;
Content-Type:text/html;charset=\"UTF-8\";

"
subject := fmt.Sprintf("Subject: %s
", r.FormValue("subject"))
msg := []byte(subject + mime + body)

err := smtp.SendMail("localhost:25", nil, from, to, msg)

The email was sent/received fine. However, it is missing the receipt address in the To field of received email. I also tried it on an exchange server. The receipt addresses are missing as well. Here is what it shows in the email source.

To: Undisclosed recipients:;

Any suggestions to fix it? thanks!

  • 写回答

1条回答 默认 最新

  • douwu8524 2015-07-14 20:45
    关注

    You're setting the values for the mail envelope, but you haven't put any headers in the email itself except for Subject:. You should also be using as a newline for email.

    A minimal example might look like:

    headers := make(map[string]string)
    
    headers["Subject"] = "this is a test"
    headers["From"] = "me@example.com"
    headers["To"] = "you@example.com"
    
    body := "hello,
    this is a test"
    
    var msg bytes.Buffer
    for k, v := range headers {
        msg.WriteString(k + ": " + v + "
    ")
    }
    
    msg.WriteString("
    ")
    msg.WriteString(body)
    

    Some other helpful stdlib packages:

    评论

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?