Documentation
¶
Overview ¶
Package mailgun provides a Mailgun provider adapter for the goemail library.
It implements the email.Sender interface using the Mailgun v3 Messages API, allowing you to send emails through Mailgun without pulling in any external SDK dependencies.
Usage ¶
sender, err := mailgun.New(mailgun.Config{
Domain: "mg.example.com",
APIKey: os.Getenv("MAILGUN_API_KEY"),
})
if err != nil {
log.Fatal(err)
}
defer sender.Close()
e, _ := email.NewEmail().
SetFrom("sender@mg.example.com").
AddTo("recipient@example.com").
SetSubject("Hello from Mailgun").
SetBody("Plain text body").
Build()
err = sender.Send(context.Background(), e)
EU Region ¶
For EU-based Mailgun accounts, set the BaseURL:
sender, _ := mailgun.New(mailgun.Config{
Domain: "mg.example.com",
APIKey: os.Getenv("MAILGUN_API_KEY"),
BaseURL: "https://api.eu.mailgun.net",
})
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Domain is the Mailgun sending domain (required, e.g., "mg.example.com").
Domain string
// APIKey is the Mailgun API key (required).
APIKey string
// BaseURL is the Mailgun API base URL.
// Default: "https://api.mailgun.net".
// For EU accounts use "https://api.eu.mailgun.net".
BaseURL string
// HTTPClient is the HTTP client used for API calls.
// Default: http.DefaultClient.
HTTPClient *http.Client
}
Config holds the Mailgun provider configuration.
Click to show internal directories.
Click to hide internal directories.