duanrenchuo9244 2017-09-22 16:48
浏览 166
已采纳

如何在golang net / smtp.sendmail中定义发件人名称?

My question is short, I have a golang application from which I am trying to send an email using net/smtp.sendmail:

This is the command which I am going to use

smtp.SendMail(server, auth, **from**, to, msg)

No usually people pass the sender's email address to from. Is there anyway I can pass a sender's name as well?

So the recipient will get an email from:

Foo Bar <foo@bar.com>

instead of an email from

<foo@bar.com>

I checked the official documentation and dozens of examples online but could not find anything.

Thank you.

  • 写回答

1条回答 默认 最新

  • douyun6781 2017-09-22 17:16
    关注

    You could add it to the msg for example, extending the example from the official docs you could use:

    msg := []byte("From: the name <sender@example.org>
    " +
            "To: recipient@example.net
    " +
            "Subject: discount Gophers!
    " +
            "
    " +
            "This is the email body.
    ")
    

    Notice the: From: the name <sender@example.org>

    The msg parameter should be an RFC 822-style email with headers first, a blank line, and then the message body. The lines of msg should be CRLF terminated. The msg headers should usually include fields such as "From", "To", "Subject", and "Cc".

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

报告相同问题?

悬赏问题

  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退