如何在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.

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".