This project provides implementations for sending emails using different services including SMTP, Gmail API, Microsoft Graph API, SendGrid, AWS SES, Mailgun, Mandrill, Postmark, and SparkPost. Each implementation follows a common interface, allowing for flexibility and easy integration with various email services.
- Send emails using various providers: SMTP, Gmail API, Microsoft Graph API, SendGrid, AWS SES, Mailgun, Mandrill, Postmark, SparkPost.
- Support for attachments and both plain text and HTML content.
- Easy configuration and setup.
- Go 1.22+
- Access to the relevant email service provider (SMTP server, Gmail, Microsoft 365, SendGrid, AWS SES, Mailgun, Mandrill, Postmark, SparkPost)
go get github.com/darkrockmountain/gomail
- Alternatively download repository:
git clone https://github.com/darkrockmountain/gomail.git cd gomail
go mod tidy
- Configure your SMTP server settings in
providers/smpt/smtp_email_sender.go
. - Refer to the SMTP Credentials Documentation for details on obtaining credentials.
- Run the
smtpExample()
function to send a test email.
- Configure your Gmail API credentials in
providers/gmail/gmail_email_sender.go
. - Refer to the Gmail Credentials Documentation for details on obtaining credentials.
- Run the
gExample()
function to send a test email.
- Configure your Gmail API credentials and token in
providers/gmail/gmail_email_sender_oauth2.go
. - Refer to the Gmail OAuth2 Credentials Documentation for details on obtaining credentials.
- Run the
gExampleOauth2()
function to send a test email.
- Configure your Microsoft Graph API credentials in
providers/microsoft365/microsoft365_email_sender.go
. - Refer to the Microsoft 365 Credentials Documentation for details on obtaining credentials.
- Run the
msGraphExample()
function to send a test email.
- Configure your SendGrid API key in
providers/sendgrid/sendgrid_email_sender.go
. - Refer to the SendGrid Credentials Documentation for details on obtaining credentials.
- Run the
sendgridExample()
function to send a test email.
- Configure your AWS SES credentials in
providers/ses/ses_email_sender.go
. - Refer to the AWS SES Credentials Documentation for details on obtaining credentials.
- Run the
sesExample()
function to send a test email.
- Configure your Mailgun API key in
providers/mailgun/mailgun_email_sender.go
. - Refer to the Mailgun Credentials Documentation for details on obtaining credentials.
- Run the
mailgunExample()
function to send a test email.
- Configure your Mandrill API key in
providers/mandrill/mandrill_email_sender.go
. - Refer to the Mandrill Credentials Documentation for details on obtaining credentials.
- Run the
mandrillExample()
function to send a test email.
- Configure your Postmark API key in
providers/postmark/postmark_email_sender.go
. - Refer to the Postmark Credentials Documentation for details on obtaining credentials.
- Run the
postmarkExample()
function to send a test email.
- Configure your SparkPost API key in
providers/sparkpost/sparkpost_email_sender.go
. - Refer to the SparkPost Documentation for details on obtaining credentials.
- Run the
sparkpostExample()
function to send a test email.
For detailed instructions on obtaining the necessary credentials for each implementation, refer to the respective documentation files in the docs
directory.
This project is licensed under the Apache-2.0 License - see the LICENSE file for details.
- Authentication Failed: Ensure your API keys and credentials are correct and have the necessary permissions.
- Network Issues: Verify your network connectivity and ensure your server can reach the email service provider.
- Invalid Email Addresses: Check that all email addresses are correctly formatted.
- Attachment Issues: Ensure attachments are correctly encoded and within size limits.
- Check Logs: Always check your application logs for detailed error messages.
- Validate Credentials: Double-check your credentials and permissions.
- API Limits: Ensure you are not exceeding API rate limits or quotas.
- Service Status: Verify that the email service provider is operational and not experiencing downtime.
- Environment Variables: Use environment variables to store credentials.
- Secret Managers: Use secret management services like AWS Secrets Manager, Google Secret Manager, or HashiCorp Vault.
- Encryption: Encrypt sensitive information both at rest and in transit.
- Least Privilege: Follow the principle of least privilege for API keys and credentials.