Documentation ¶
Overview ¶
Package providers provides functionality for sending emails using various providers.
Overview ¶
The providers package allows you to send emails using different email providers such as Gmail, SendGrid, AWS SES, and others. It abstracts the provider-specific details and provides a simple API for sending emails.
Usage ¶
To use the package, you need to create an instance of the email sender for your desired provider and then call the SendEmail function.
Example:
package main import ( "github.com/darkrockmountain/gomail" ) func main() { sender := providers.NewSendGridEmailSender("your-api-key") err := sender.SendEmail("recipient@example.com", "Subject", "Email body") if err != nil { log.Fatal(err) } }
This package supports various email providers and can be extended to include more.
Supported Providers ¶
- Gmail - SendGrid - AWS SES - Mailgun - Mandrill - Postmark - Microsoft365 - SparkPost - SMTP
mandrill_email_sender.go
Index ¶
- func NewGmailEmailSenderAPIKey(ctx context.Context, apiKey, user string) (*gmailMessageSenderWrapper, error)
- func NewGmailEmailSenderJWT(ctx context.Context, configJson []byte, user string) (*gmailMessageSenderWrapper, error)
- func NewGmailEmailSenderJWTAccess(ctx context.Context, jsonCredentials []byte, user string) (*gmailMessageSenderWrapper, error)
- func NewGmailEmailSenderOauth2(ctx context.Context, configJson []byte, tokenManager GmailTokenManager, ...) (*gmailMessageSenderWrapper, error)
- func NewGmailEmailSenderServiceAccount(ctx context.Context, jsonCredentials []byte, user string) (*gmailMessageSenderWrapper, error)
- func NewMSGraphEmailSenderAppAuth(clientId, tenantId, clientSecret, user string) (*mSGraphEmailSender, error)
- func NewMSGraphEmailSenderManagedIdentity(user string) (*mSGraphEmailSender, error)
- func NewMSGraphEmailSenderROPC(clientId, tenantId, username, password string) (*mSGraphEmailSender, error)
- func NewMSGraphEmailSenderUserAuth(clientId, tenantId string) (*mSGraphEmailSender, error)
- func NewMailgunEmailSender(domain, apiKey string) (*mailgunEmailSender, error)
- func NewMandrillEmailSender(apiKey string) (*mandrillEmailSender, error)
- func NewPostmarkEmailSender(serverToken string) (*postmarkEmailSender, error)
- func NewSESEmailSender(region, sender string) (*sESEmailSender, error)
- func NewSESEmailSenderWithCredentials(region, sender, accessKeyID, secretAccessKey string) (*sESEmailSender, error)
- func NewSendGridEmailSender(apiKey string) (*sendGridEmailSender, error)
- func NewSmtpEmailSender(host string, port int, user, password string, authMethod AuthMethod) (*smtpEmailSender, error)
- func NewSmtpEmailSenderWithConnMethod(host string, port int, user, password string, authMethod AuthMethod, ...) (*smtpEmailSender, error)
- func NewSparkPostEmailSender(apiKey string) (*sparkPostEmailSender, error)
- type AuthMethod
- type ConnectionMethod
- type GmailTokenManager
- type MailgunSubSet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewGmailEmailSenderAPIKey ¶
func NewGmailEmailSenderAPIKey(ctx context.Context, apiKey, user string) (*gmailMessageSenderWrapper, error)
NewGmailEmailSenderAPIKey initializes a new gmailEmailSenderAPIKey instance using an API key. Parameters:
- ctx: The context for the API requests.
- apiKey: The API key to be used for authentication.
- user: The user for whom the email is being sent (usually "me").
Returns:
- *gmailMessageSenderWrapper: A pointer to the initialized gmailMessageSenderWrapper.
- error: An error if the initialization fails.
func NewGmailEmailSenderJWT ¶
func NewGmailEmailSenderJWT(ctx context.Context, configJson []byte, user string) (*gmailMessageSenderWrapper, error)
NewGmailEmailSenderJWT initializes a new gmailEmailSenderJWT instance using JWT configuration. Parameters:
- ctx: The context for the API requests.
- configJson: A byte slice containing the JWT client credentials JSON.
- user: The user for whom the email is being sent (usually "me").
Returns:
- *gmailMessageSenderWrapper: A pointer to the initialized gmailMessageSenderWrapper.
- error: An error if the initialization fails.
func NewGmailEmailSenderJWTAccess ¶
func NewGmailEmailSenderJWTAccess(ctx context.Context, jsonCredentials []byte, user string) (*gmailMessageSenderWrapper, error)
NewGmailEmailSenderJWTAccess initializes a new gmailEmailSenderJWTAccess instance using a JWT access token. Parameters:
- ctx: The context for the API requests.
- jsonCredentials: A byte slice containing the JSON service account credentials.
- user: The user for whom the email is being sent.
Returns:
- *gmailMessageSenderWrapper: A pointer to the initialized gmailMessageSenderWrapper.
- error: An error if the initialization fails.
func NewGmailEmailSenderOauth2 ¶
func NewGmailEmailSenderOauth2(ctx context.Context, configJson []byte, tokenManager GmailTokenManager, user string) (*gmailMessageSenderWrapper, error)
NewGmailEmailSenderOauth2 initializes a new gmailEmailSenderOauth2 instance using OAuth2 credentials and token management. Parameters:
- ctx: The context for the API requests.
- configJson: A byte slice containing the OAuth2 client credentials JSON.
- tokenManager: An implementation of the GmailTokenManager interface.
- user: The user for whom the email is being sent (usually "me").
Returns:
- *gmailMessageSenderWrapper: A pointer to the initialized gmailMessageSenderWrapper.
- error: An error if the initialization fails.
func NewGmailEmailSenderServiceAccount ¶
func NewGmailEmailSenderServiceAccount(ctx context.Context, jsonCredentials []byte, user string) (*gmailMessageSenderWrapper, error)
NewGmailEmailSenderServiceAccount initializes a new gmailEmailSenderServiceAccount instance using service account JSON credentials. Parameters:
- ctx: The context for the API requests.
- jsonCredentials: A byte slice containing the JSON service account credentials.
- user: The user for whom the email is being sent.
Returns:
- *gmailMessageSenderWrapper: A pointer to the initialized gmailMessageSenderWrapper.
- error: An error if the initialization fails.
func NewMSGraphEmailSenderAppAuth ¶
func NewMSGraphEmailSenderAppAuth(clientId, tenantId, clientSecret, user string) (*mSGraphEmailSender, error)
NewMSGraphEmailSenderAppAuth creates a new instance of mSGraphEmailSender with application authentication. It initializes the Microsoft Graph email sender with the provided Azure AD client credentials.
Parameters:
- clientId: The client ID of the Azure AD application.
- tenantId: The tenant ID of the Azure AD directory.
- clientSecret: The client secret of the Azure AD application.
- user: The user account from where the emails will be sent. Can be a real user or a shared mailbox.
Returns:
- *mSGraphEmailSender: A pointer to the initialized mSGraphEmailSender.
- error: An error if the initialization fails, otherwise nil.
func NewMSGraphEmailSenderManagedIdentity ¶
NewMSGraphEmailSenderManagedIdentity creates a new instance of mSGraphEmailSender using Managed Identity authentication. It initializes the Microsoft Graph email sender with the provided Azure AD managed identity credentials.
Parameters:
- user: The user account from where the emails will be sent. Can be a real user or a shared mailbox.
Returns:
- *mSGraphEmailSender: A pointer to the initialized mSGraphEmailSender.
- error: An error if the initialization fails, otherwise nil.
func NewMSGraphEmailSenderROPC ¶
func NewMSGraphEmailSenderROPC(clientId, tenantId, username, password string) (*mSGraphEmailSender, error)
NewMSGraphEmailSenderROPC creates a new instance of mSGraphEmailSender using Resource Owner Password Credentials (ROPC) authentication. It initializes the Microsoft Graph email sender with the provided Azure AD client credentials and user credentials.
Parameters:
- clientId: The client ID of the Azure AD application.
- tenantId: The tenant ID of the Azure AD directory.
- username: The username of the user.
- password: The password of the user.
Returns:
- *mSGraphEmailSender: A pointer to the initialized mSGraphEmailSender.
- error: An error if the initialization fails, otherwise nil.
func NewMSGraphEmailSenderUserAuth ¶
NewMSGraphEmailSenderUserAuth creates a new instance of mSGraphEmailSender with user (delegated) authentication. It initializes the Microsoft Graph email sender with the provided Azure AD client credentials using delegated authentication.
Parameters:
- clientId: The client ID of the Azure AD application.
- tenantId: The tenant ID of the Azure AD directory.
Returns:
- *mSGraphEmailSender: A pointer to the initialized mSGraphEmailSender.
- error: An error if the initialization fails, otherwise nil.
func NewMailgunEmailSender ¶
NewMailgunEmailSender creates a new instance of mailgunEmailSender. It initializes the Mailgun email sender with the provided domain and API key.
Parameters:
- domain: The Mailgun domain to be used for sending emails.
- apiKey: The API key to be used for authentication.
Returns:
- *mailgunEmailSender: A pointer to the initialized mailgunEmailSender.
- error: An error if the initialization fails, otherwise nil.
func NewMandrillEmailSender ¶
NewMandrillEmailSender creates a new instance of mandrillEmailSender. It initializes the Mandrill email sender with the provided API key.
Parameters:
- apiKey: The API key to be used for authentication.
Returns:
- *mandrillEmailSender: A pointer to the initialized mandrillEmailSender.
- error: An error if the initialization fails, otherwise nil.
func NewPostmarkEmailSender ¶
NewPostmarkEmailSender creates a new instance of postmarkEmailSender. It initializes the Postmark email sender with the provided server token.
Parameters:
- serverToken: The server token to be used for authentication.
Returns:
- *postmarkEmailSender: A pointer to the initialized postmarkEmailSender.
- error: An error if the initialization fails, otherwise nil.
func NewSESEmailSender ¶
NewSESEmailSender creates a new instance of SESEmailSender. It initializes the SES email sender with the provided AWS region and sender email address.
Parameters:
- region: The AWS region to be used for sending emails.
- sender: The email address to be used as the sender.
Returns:
- *SESEmailSender: A pointer to the initialized SESEmailSender.
- error: An error if the initialization fails, otherwise nil.
func NewSESEmailSenderWithCredentials ¶
func NewSESEmailSenderWithCredentials(region, sender, accessKeyID, secretAccessKey string) (*sESEmailSender, error)
NewSESEmailSenderWithCredentials creates a new instance of SESEmailSender. It initializes the SES email sender with the provided AWS region, sender email address, and AWS credentials.
Parameters:
- region: The AWS region to be used for sending emails.
- sender: The email address to be used as the sender.
- accessKeyID: The AWS access key ID.
- secretAccessKey: The AWS secret access key.
Returns:
- *SESEmailSender: A pointer to the initialized SESEmailSender.
- error: An error if the initialization fails, otherwise nil.
func NewSendGridEmailSender ¶
NewSendGridEmailSender creates a new instance of sendGridEmailSender. It initializes the SendGrid email sender with the provided API key.
Parameters:
- apiKey: The API key to be used for authentication.
Returns:
- *sendGridEmailSender: A pointer to the initialized sendGridEmailSender.
- error: An error if the initialization fails, otherwise nil.
func NewSmtpEmailSender ¶
func NewSmtpEmailSender(host string, port int, user, password string, authMethod AuthMethod) (*smtpEmailSender, error)
Returns:
- *smtpEmailSender: A pointer to the initialized smtpEmailSender.
- error: An error if the initialization fails, otherwise nil.
func NewSmtpEmailSenderWithConnMethod ¶
func NewSmtpEmailSenderWithConnMethod(host string, port int, user, password string, authMethod AuthMethod, connectionMethod ConnectionMethod) (*smtpEmailSender, error)
Returns:
- *smtpEmailSender: A pointer to the initialized smtpEmailSender.
- error: An error if the initialization fails, otherwise nil.
func NewSparkPostEmailSender ¶
NewSparkPostEmailSender creates a new instance of sparkPostEmailSender. It initializes the SparkPost email sender with the provided API key.
Parameters:
- apiKey: The API key to be used for authentication.
Returns:
- *sparkPostEmailSender: A pointer to the initialized sparkPostEmailSender.
- error: An error if the initialization fails, otherwise nil.
Types ¶
type AuthMethod ¶
type AuthMethod string
AuthMethod defines the authorization method for SMTP.
const ( AUTH_CRAM_MD5 AuthMethod = "CRAM-MD5" // CRAM-MD5 authentication method. AUTH_PLAIN AuthMethod = "PLAIN" // Plain authentication method. )
type ConnectionMethod ¶
type ConnectionMethod string
const ( CONN_IMPLICIT ConnectionMethod = "IMPLICIT" // IMPLICIT TLS authentication method. CONN_TLS ConnectionMethod = "TLS" // TLS authentication method. )
type GmailTokenManager ¶
GmailTokenManager defines an interface for obtaining OAuth2 tokens.