Skip to content

net/smtp: package document does not explain how to add subject and body in msg parameter #9776

Description

@1002nights

The net/smtp package document does not mention how to add subject and body for emails sent. http://golang.org/pkg/net/smtp/#SendMail

Here is an example of one way to have both subject and body text -

auth := smtp.PlainAuth(
"",
"email@example.com",
"password",
"smtp.example.com",
)

// Connect to the server, authenticate, set the sender and recipient,
// and send the email all in one step
// The Byte array provides both Subject and body
err := smtp.SendMail(
"smtp.example.com:587",
auth,
"me@example.com",
[]string{recipient@example.com},
[]byte("Subject: Test Subject Text \r\n\r\n Test Email Body Text"),
)

if err != nil {
fmt.Println("Email Error: ", err)
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions