go-mailgun is a simple library that sends email messages via Mailgun.
Before sending any emails, an account on Mailgun is required, and a domain must be configured and an API key created.
There are two ways to send email through Mailgun using this module.
- Specify individual fields of the message
- create a MIME email message and send that.
A Mailgun client is configured by passing in the API key and the domain
mg_client := mailgun.NewClient("YOUR-API-KEY-HERE", "YOUR-DOMAIN-HERE.mailgun.org")
This is a simple way to send mail through the API. When sending a message, the sender's email address, the recipient's email address, the subject, and the body must all be specified.
message := mailgun.Message{
FromName: "Foo From",
FromAddress: "foo@fakedomaingoeshere.com",
ToAddress: "bar@anotherfakedomainhere.com",
Subject: "test message",
Body: "This is the body of the message. It's not very interesting.",
}
mg_client.Send(message)
This part of the API will take a MIME message and send it via Mailgun's MIME endpoint. It does not do any validation on the MIME message passed in.
mime_message := mailgun.MimeMessage{
ToAddress: "sent_to_address@fakedomainhere.com",
Content: mimeContents}
mg_client.Send(message2)
See the example app (from which most of the above code was ripped).
Licensed under the Apache 2.0 license.