From 49b7ed6ab3f411c70efc0996ea36775982f226df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Rocabruna?= Date: Tue, 4 Jun 2024 13:56:54 +0200 Subject: [PATCH 1/2] refactor: separate all email providers into individual packages --- providers/{ => gmail}/gmail_email_sender.go | 5 +++-- providers/{ => gmail}/gmail_email_sender_test.go | 2 +- providers/helper_functions.go | 14 +++++++------- providers/helper_functions_test.go | 2 +- providers/{ => mailgun}/mailgun_email_sender.go | 2 +- .../{ => mailgun}/mailgun_email_sender_test.go | 2 +- providers/{ => mandrill}/mandrill_email_sender.go | 2 +- .../{ => mandrill}/mandrill_email_sender_test.go | 2 +- .../microsoft365_email_sender.go | 12 ++++++------ .../microsoft365_email_sender_test.go | 2 +- providers/{ => postmark}/postmark_email_sender.go | 2 +- .../{ => postmark}/postmark_email_sender_test.go | 2 +- providers/{ => sendgrid}/sendgrid_email_sender.go | 2 +- .../{ => sendgrid}/sendgrid_email_sender_test.go | 2 +- providers/{ => ses}/ses_email_sender.go | 2 +- providers/{ => ses}/ses_email_sender_test.go | 2 +- providers/{ => smtp}/smtp_email_sender.go | 6 +++--- providers/{ => smtp}/smtp_email_sender_test.go | 2 +- .../{ => sparkpost}/sparkpost_email_sender.go | 2 +- .../{ => sparkpost}/sparkpost_email_sender_test.go | 2 +- 20 files changed, 35 insertions(+), 34 deletions(-) rename providers/{ => gmail}/gmail_email_sender.go (98%) rename providers/{ => gmail}/gmail_email_sender_test.go (99%) rename providers/{ => mailgun}/mailgun_email_sender.go (99%) rename providers/{ => mailgun}/mailgun_email_sender_test.go (99%) rename providers/{ => mandrill}/mandrill_email_sender.go (99%) rename providers/{ => mandrill}/mandrill_email_sender_test.go (99%) rename providers/{ => microsoft365}/microsoft365_email_sender.go (97%) rename providers/{ => microsoft365}/microsoft365_email_sender_test.go (99%) rename providers/{ => postmark}/postmark_email_sender.go (99%) rename providers/{ => postmark}/postmark_email_sender_test.go (99%) rename providers/{ => sendgrid}/sendgrid_email_sender.go (99%) rename providers/{ => sendgrid}/sendgrid_email_sender_test.go (99%) rename providers/{ => ses}/ses_email_sender.go (99%) rename providers/{ => ses}/ses_email_sender_test.go (99%) rename providers/{ => smtp}/smtp_email_sender.go (97%) rename providers/{ => smtp}/smtp_email_sender_test.go (99%) rename providers/{ => sparkpost}/sparkpost_email_sender.go (99%) rename providers/{ => sparkpost}/sparkpost_email_sender_test.go (99%) diff --git a/providers/gmail_email_sender.go b/providers/gmail/gmail_email_sender.go similarity index 98% rename from providers/gmail_email_sender.go rename to providers/gmail/gmail_email_sender.go index b8b34d0..70c5c67 100644 --- a/providers/gmail_email_sender.go +++ b/providers/gmail/gmail_email_sender.go @@ -1,4 +1,4 @@ -package providers +package gmail import ( "bytes" @@ -10,6 +10,7 @@ import ( "github.com/darkrockmountain/gomail" "github.com/darkrockmountain/gomail/credentials" + "github.com/darkrockmountain/gomail/providers" "golang.org/x/oauth2/google" "google.golang.org/api/gmail/v1" "google.golang.org/api/option" @@ -47,7 +48,7 @@ func (ms *gmailMessageSenderWrapper) send(message *gmail.Message) (*gmail.Messag // Returns: // - error: An error if sending the email fails. func (s *gmailMessageSenderWrapper) SendEmail(message gomail.EmailMessage) error { - mimeMessage, err := buildMimeMessage(message) + mimeMessage, err := providers.BuildMimeMessage(message) if err != nil { return fmt.Errorf("unable to build MIME message: %w", err) } diff --git a/providers/gmail_email_sender_test.go b/providers/gmail/gmail_email_sender_test.go similarity index 99% rename from providers/gmail_email_sender_test.go rename to providers/gmail/gmail_email_sender_test.go index d392a8a..8f5cac3 100644 --- a/providers/gmail_email_sender_test.go +++ b/providers/gmail/gmail_email_sender_test.go @@ -1,4 +1,4 @@ -package providers +package gmail import ( "bytes" diff --git a/providers/helper_functions.go b/providers/helper_functions.go index e5e7b16..42c1b7a 100644 --- a/providers/helper_functions.go +++ b/providers/helper_functions.go @@ -9,7 +9,7 @@ import ( "github.com/darkrockmountain/gomail" ) -// buildMimeMessage constructs the MIME message for the email, including text, HTML, and attachments. +// BuildMimeMessage constructs the MIME message for the email, including text, HTML, and attachments. // This function builds a multipart MIME message based on the provided email message. It supports plain text, // HTML content, and multiple attachments. // @@ -35,12 +35,12 @@ import ( // }, // }, // } -// mimeMessage, err := buildMimeMessage(message) +// mimeMessage, err := BuildMimeMessage(message) // if err != nil { // log.Fatalf("Failed to build MIME message: %v", err) // } // fmt.Println(string(mimeMessage)) -func buildMimeMessage(message gomail.EmailMessage) ([]byte, error) { +func BuildMimeMessage(message gomail.EmailMessage) ([]byte, error) { var msg bytes.Buffer // Determine boundaries @@ -127,7 +127,7 @@ func buildMimeMessage(message gomail.EmailMessage) ([]byte, error) { return msg.Bytes(), nil } -// strPtr takes a string value and returns a pointer to that string. +// StrPtr takes a string value and returns a pointer to that string. // This function is useful when you need to work with string pointers, such as in // scenarios where you need to pass a string by reference or handle optional string fields. // @@ -140,12 +140,12 @@ func buildMimeMessage(message gomail.EmailMessage) ([]byte, error) { // Example usage: // // name := "John Doe" -// namePtr := strPtr(name) +// namePtr := StrPtr(name) // fmt.Println(namePtr) // Output: memory address of the string // fmt.Println(*namePtr) // Output: "John Doe" // // Detailed explanation: -// The strPtr function creates a pointer to the given string `str`. +// The StrPtr function creates a pointer to the given string `str`. // This can be particularly useful in the following scenarios: // 1. Passing strings by reference to functions, which can help avoid copying large strings. // 2. Working with data structures that use pointers to represent optional fields or nullable strings. @@ -153,6 +153,6 @@ func buildMimeMessage(message gomail.EmailMessage) ([]byte, error) { // // By using this function, you can easily obtain a pointer to a string and utilize it in contexts // where pointers are needed, thus enhancing flexibility and efficiency in your Go programs. -func strPtr(str string) *string { +func StrPtr(str string) *string { return &str } diff --git a/providers/helper_functions_test.go b/providers/helper_functions_test.go index 10150bc..18a9b92 100644 --- a/providers/helper_functions_test.go +++ b/providers/helper_functions_test.go @@ -49,7 +49,7 @@ func TestBuildMimeMessage(t *testing.T) { for _, test := range tests { t.Run(test.message.Subject, func(t *testing.T) { - result, err := buildMimeMessage(test.message) + result, err := BuildMimeMessage(test.message) if err != nil { t.Fatalf("unexpected error: %v", err) } diff --git a/providers/mailgun_email_sender.go b/providers/mailgun/mailgun_email_sender.go similarity index 99% rename from providers/mailgun_email_sender.go rename to providers/mailgun/mailgun_email_sender.go index 2dce564..543e9b0 100644 --- a/providers/mailgun_email_sender.go +++ b/providers/mailgun/mailgun_email_sender.go @@ -1,4 +1,4 @@ -package providers +package mailgun import ( "context" diff --git a/providers/mailgun_email_sender_test.go b/providers/mailgun/mailgun_email_sender_test.go similarity index 99% rename from providers/mailgun_email_sender_test.go rename to providers/mailgun/mailgun_email_sender_test.go index 0bbcea8..3d44a31 100644 --- a/providers/mailgun_email_sender_test.go +++ b/providers/mailgun/mailgun_email_sender_test.go @@ -1,4 +1,4 @@ -package providers +package mailgun import ( "context" diff --git a/providers/mandrill_email_sender.go b/providers/mandrill/mandrill_email_sender.go similarity index 99% rename from providers/mandrill_email_sender.go rename to providers/mandrill/mandrill_email_sender.go index 6c21de0..b2f1c05 100644 --- a/providers/mandrill_email_sender.go +++ b/providers/mandrill/mandrill_email_sender.go @@ -1,5 +1,5 @@ // mandrill_email_sender.go -package providers +package mandrill import ( "bytes" diff --git a/providers/mandrill_email_sender_test.go b/providers/mandrill/mandrill_email_sender_test.go similarity index 99% rename from providers/mandrill_email_sender_test.go rename to providers/mandrill/mandrill_email_sender_test.go index c00ebc3..c95d217 100644 --- a/providers/mandrill_email_sender_test.go +++ b/providers/mandrill/mandrill_email_sender_test.go @@ -1,4 +1,4 @@ -package providers +package mandrill import ( "net/http" diff --git a/providers/microsoft365_email_sender.go b/providers/microsoft365/microsoft365_email_sender.go similarity index 97% rename from providers/microsoft365_email_sender.go rename to providers/microsoft365/microsoft365_email_sender.go index 9ee878d..8f0e8b5 100644 --- a/providers/microsoft365_email_sender.go +++ b/providers/microsoft365/microsoft365_email_sender.go @@ -1,4 +1,4 @@ -package providers +package microsoft365 import ( "context" @@ -6,6 +6,7 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/azidentity" "github.com/darkrockmountain/gomail" + "github.com/darkrockmountain/gomail/providers" azureAuth "github.com/microsoft/kiota-authentication-azure-go" msgraph "github.com/microsoftgraph/msgraph-sdk-go" "github.com/microsoftgraph/msgraph-sdk-go/models" @@ -59,15 +60,14 @@ func composeMsMessage(message gomail.EmailMessage) *models.Message { if message.GetHTML() != "" { htmlBodyType := models.HTML_BODYTYPE body.SetContentType(&htmlBodyType) - body.SetContent(strPtr(message.GetHTML())) + body.SetContent(providers.StrPtr(message.GetHTML())) } else { textBodyType := models.TEXT_BODYTYPE body.SetContentType(&textBodyType) - body.SetContent(strPtr(message.GetText())) + body.SetContent(providers.StrPtr(message.GetText())) } - msMessage := models.NewMessage() - msMessage.SetSubject(strPtr(message.GetSubject())) + msMessage.SetSubject(providers.StrPtr(message.GetSubject())) msMessage.SetBody(body) // Add sender @@ -138,7 +138,7 @@ func composeMsMessage(message gomail.EmailMessage) *models.Message { msAttachments := make([]models.Attachmentable, len(attachments)) for i, attachment := range attachments { fileAttachment := models.NewFileAttachment() - fileAttachment.SetName(strPtr(attachment.GetFilename())) + fileAttachment.SetName(providers.StrPtr(attachment.GetFilename())) fileAttachment.SetContentBytes([]byte(attachment.GetBase64StringContent())) msAttachments[i] = fileAttachment } diff --git a/providers/microsoft365_email_sender_test.go b/providers/microsoft365/microsoft365_email_sender_test.go similarity index 99% rename from providers/microsoft365_email_sender_test.go rename to providers/microsoft365/microsoft365_email_sender_test.go index 8f07a2f..abb07b8 100644 --- a/providers/microsoft365_email_sender_test.go +++ b/providers/microsoft365/microsoft365_email_sender_test.go @@ -1,4 +1,4 @@ -package providers +package microsoft365 import ( "bytes" diff --git a/providers/postmark_email_sender.go b/providers/postmark/postmark_email_sender.go similarity index 99% rename from providers/postmark_email_sender.go rename to providers/postmark/postmark_email_sender.go index 9f2de5f..526e293 100644 --- a/providers/postmark_email_sender.go +++ b/providers/postmark/postmark_email_sender.go @@ -1,4 +1,4 @@ -package providers +package postmark import ( "bytes" diff --git a/providers/postmark_email_sender_test.go b/providers/postmark/postmark_email_sender_test.go similarity index 99% rename from providers/postmark_email_sender_test.go rename to providers/postmark/postmark_email_sender_test.go index da591fe..0c6b440 100644 --- a/providers/postmark_email_sender_test.go +++ b/providers/postmark/postmark_email_sender_test.go @@ -1,4 +1,4 @@ -package providers +package postmark import ( "net/http" diff --git a/providers/sendgrid_email_sender.go b/providers/sendgrid/sendgrid_email_sender.go similarity index 99% rename from providers/sendgrid_email_sender.go rename to providers/sendgrid/sendgrid_email_sender.go index 5326266..5f14a3c 100644 --- a/providers/sendgrid_email_sender.go +++ b/providers/sendgrid/sendgrid_email_sender.go @@ -1,4 +1,4 @@ -package providers +package sendgrid import ( "fmt" diff --git a/providers/sendgrid_email_sender_test.go b/providers/sendgrid/sendgrid_email_sender_test.go similarity index 99% rename from providers/sendgrid_email_sender_test.go rename to providers/sendgrid/sendgrid_email_sender_test.go index 1793605..356119d 100644 --- a/providers/sendgrid_email_sender_test.go +++ b/providers/sendgrid/sendgrid_email_sender_test.go @@ -1,4 +1,4 @@ -package providers +package sendgrid import ( "encoding/base64" diff --git a/providers/ses_email_sender.go b/providers/ses/ses_email_sender.go similarity index 99% rename from providers/ses_email_sender.go rename to providers/ses/ses_email_sender.go index 6d156d1..684ee63 100644 --- a/providers/ses_email_sender.go +++ b/providers/ses/ses_email_sender.go @@ -1,4 +1,4 @@ -package providers +package ses import ( "fmt" diff --git a/providers/ses_email_sender_test.go b/providers/ses/ses_email_sender_test.go similarity index 99% rename from providers/ses_email_sender_test.go rename to providers/ses/ses_email_sender_test.go index c1c5cfe..753ef07 100644 --- a/providers/ses_email_sender_test.go +++ b/providers/ses/ses_email_sender_test.go @@ -1,4 +1,4 @@ -package providers +package ses import ( "errors" diff --git a/providers/smtp_email_sender.go b/providers/smtp/smtp_email_sender.go similarity index 97% rename from providers/smtp_email_sender.go rename to providers/smtp/smtp_email_sender.go index 1ed8307..895b659 100644 --- a/providers/smtp_email_sender.go +++ b/providers/smtp/smtp_email_sender.go @@ -1,4 +1,4 @@ -package providers +package smtp import ( "crypto/tls" @@ -7,6 +7,7 @@ import ( "os" "github.com/darkrockmountain/gomail" + "github.com/darkrockmountain/gomail/providers" ) // smtpEmailSender is responsible for sending emails using SMTP. @@ -86,8 +87,7 @@ func (s *smtpEmailSender) SendEmail(message gomail.EmailMessage) error { sendMailTo := message.GetTo() sendMailTo = append(sendMailTo, message.GetCC()...) sendMailTo = append(sendMailTo, message.GetBCC()...) - - msg, err := buildMimeMessage(message) + msg, err := providers.BuildMimeMessage(message) if err != nil { return err } diff --git a/providers/smtp_email_sender_test.go b/providers/smtp/smtp_email_sender_test.go similarity index 99% rename from providers/smtp_email_sender_test.go rename to providers/smtp/smtp_email_sender_test.go index f5baad5..7629009 100644 --- a/providers/smtp_email_sender_test.go +++ b/providers/smtp/smtp_email_sender_test.go @@ -1,4 +1,4 @@ -package providers +package smtp import ( "crypto/tls" diff --git a/providers/sparkpost_email_sender.go b/providers/sparkpost/sparkpost_email_sender.go similarity index 99% rename from providers/sparkpost_email_sender.go rename to providers/sparkpost/sparkpost_email_sender.go index e59859c..a4bfc05 100644 --- a/providers/sparkpost_email_sender.go +++ b/providers/sparkpost/sparkpost_email_sender.go @@ -1,4 +1,4 @@ -package providers +package sparkpost import ( "fmt" diff --git a/providers/sparkpost_email_sender_test.go b/providers/sparkpost/sparkpost_email_sender_test.go similarity index 99% rename from providers/sparkpost_email_sender_test.go rename to providers/sparkpost/sparkpost_email_sender_test.go index 8094c13..66f7526 100644 --- a/providers/sparkpost_email_sender_test.go +++ b/providers/sparkpost/sparkpost_email_sender_test.go @@ -1,4 +1,4 @@ -package providers +package sparkpost import ( "crypto/tls" From a5401d2c5092c4f63909cc856e17101a333e232c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Rocabruna?= Date: Tue, 4 Jun 2024 14:13:02 +0200 Subject: [PATCH 2/2] docs(providers): update documentation to reflect new provider package structure --- .../aws_lambda/lambda_email_sender.go | 6 +++--- .../azure_functions/azure_email_sender.go | 6 +++--- .../packages/email-sender/send-post/main.go | 6 +++--- .../gcf_email_sender.go | 6 +++--- README.md | 20 +++++++++---------- docs/Gmail_Credentials_API_Key.md | 2 +- docs/Gmail_Credentials_JWT.md | 2 +- docs/Gmail_Credentials_OAuth2.md | 4 ++-- docs/Gmail_Credentials_ServiceAccount copy.md | 2 +- docs/Gmail_Credentials_ServiceAccount.md | 2 +- docs/SMTP_Credentials.md | 2 +- email_sender.go | 7 ++++--- providers/doc.go | 5 +++-- 13 files changed, 36 insertions(+), 34 deletions(-) diff --git a/.examples/.serverless/aws_lambda/lambda_email_sender.go b/.examples/.serverless/aws_lambda/lambda_email_sender.go index ecb9249..05a1bf8 100644 --- a/.examples/.serverless/aws_lambda/lambda_email_sender.go +++ b/.examples/.serverless/aws_lambda/lambda_email_sender.go @@ -10,7 +10,7 @@ import ( "github.com/aws/aws-lambda-go/events" "github.com/aws/aws-lambda-go/lambda" "github.com/darkrockmountain/gomail" - "github.com/darkrockmountain/gomail/providers" + "github.com/darkrockmountain/gomail/providers/smtp" ) // handler is the main Lambda function handler that processes the incoming API Gateway request @@ -38,11 +38,11 @@ func handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyRespo } user := os.Getenv("SMTP_USER") password := os.Getenv("SMTP_PASSWORD") - authMethod := providers.AuthMethod(os.Getenv("SMTP_AUTH_METHOD")) + authMethod := smtp.AuthMethod(os.Getenv("SMTP_AUTH_METHOD")) // Initialize the SMTP email sender with the retrieved configuration values. // You can choose any other email sender implementation by replacing NewSmtpEmailSender with another constructor. - sender, err := providers.NewSmtpEmailSender( + sender, err := smtp.NewSmtpEmailSender( host, port, user, diff --git a/.examples/.serverless/azure_functions/azure_email_sender.go b/.examples/.serverless/azure_functions/azure_email_sender.go index 443e194..0e33130 100644 --- a/.examples/.serverless/azure_functions/azure_email_sender.go +++ b/.examples/.serverless/azure_functions/azure_email_sender.go @@ -7,7 +7,7 @@ import ( "strconv" "github.com/darkrockmountain/gomail" - "github.com/darkrockmountain/gomail/providers" + "github.com/darkrockmountain/gomail/providers/smtp" ) // SendEmail is the HTTP handler that processes the incoming request @@ -31,11 +31,11 @@ func SendEmail(w http.ResponseWriter, r *http.Request) { } user := os.Getenv("SMTP_USER") password := os.Getenv("SMTP_PASSWORD") - authMethod := providers.AuthMethod(os.Getenv("SMTP_AUTH_METHOD")) + authMethod := smtp.AuthMethod(os.Getenv("SMTP_AUTH_METHOD")) // Initialize the SMTP email sender with the retrieved configuration values. // You can choose any other email sender implementation by replacing NewSmtpEmailSender with another constructor. - sender, err := providers.NewSmtpEmailSender( + sender, err := smtp.NewSmtpEmailSender( host, port, user, diff --git a/.examples/.serverless/digitalocean_functions/packages/email-sender/send-post/main.go b/.examples/.serverless/digitalocean_functions/packages/email-sender/send-post/main.go index a99669f..b609653 100644 --- a/.examples/.serverless/digitalocean_functions/packages/email-sender/send-post/main.go +++ b/.examples/.serverless/digitalocean_functions/packages/email-sender/send-post/main.go @@ -8,7 +8,7 @@ import ( "strconv" "github.com/darkrockmountain/gomail" - "github.com/darkrockmountain/gomail/providers" + "github.com/darkrockmountain/gomail/providers/smtp" ) type ResponseHeaders struct { @@ -39,9 +39,9 @@ func Main(ctx context.Context, emailReq gomail.EmailMessage) Response { } user := os.Getenv("SMTP_USER") password := os.Getenv("SMTP_PASSWORD") - authMethod := providers.AuthMethod(os.Getenv("SMTP_AUTH_METHOD")) + authMethod := smtp.AuthMethod(os.Getenv("SMTP_AUTH_METHOD")) - sender, err := providers.NewSmtpEmailSender(host, port, user, password, authMethod) + sender, err := smtp.NewSmtpEmailSender(host, port, user, password, authMethod) if err != nil { return generateResponse(http.StatusInternalServerError, "Failed to initialize email sender") diff --git a/.examples/.serverless/google_cloud_functions/gcf_email_sender.go b/.examples/.serverless/google_cloud_functions/gcf_email_sender.go index d7c8ae3..ffaf88f 100644 --- a/.examples/.serverless/google_cloud_functions/gcf_email_sender.go +++ b/.examples/.serverless/google_cloud_functions/gcf_email_sender.go @@ -8,7 +8,7 @@ import ( "github.com/GoogleCloudPlatform/functions-framework-go/functions" "github.com/darkrockmountain/gomail" - "github.com/darkrockmountain/gomail/providers" + "github.com/darkrockmountain/gomail/providers/smtp" ) func SendEmail(w http.ResponseWriter, r *http.Request) { @@ -30,9 +30,9 @@ func SendEmail(w http.ResponseWriter, r *http.Request) { } user := os.Getenv("SMTP_USER") password := os.Getenv("SMTP_PASSWORD") - authMethod := providers.AuthMethod(os.Getenv("SMTP_AUTH_METHOD")) + authMethod := smtp.AuthMethod(os.Getenv("SMTP_AUTH_METHOD")) - sender, err = providers.NewSmtpEmailSender( + sender, err = smtp.NewSmtpEmailSender( host, port, user, diff --git a/README.md b/README.md index 88046d7..a4d3ae3 100644 --- a/README.md +++ b/README.md @@ -46,52 +46,52 @@ go mod tidy ### Usage #### 1. SMTP Email Sender -- Configure your SMTP server settings in `providers/smtp_email_sender.go`. +- Configure your SMTP server settings in `providers/smpt/smtp_email_sender.go`. - Refer to the [SMTP Credentials Documentation](./docs/SMTP_Credentials.md) for details on obtaining credentials. - Run the `smtpExample()` function to send a test email. #### 2. Gmail Email Sender -- Configure your Gmail API credentials in `providers/gmail_email_sender.go`. +- Configure your Gmail API credentials in `providers/gmail/gmail_email_sender.go`. - Refer to the [Gmail Credentials Documentation](./docs/Gmail_Credentials_API_Key.md) for details on obtaining credentials. - Run the `gExample()` function to send a test email. #### 3. Gmail Email Sender using OAuth2 -- Configure your Gmail API credentials and token in `providers/gmail_email_sender_oauth2.go`. +- Configure your Gmail API credentials and token in `providers/gmail/gmail_email_sender_oauth2.go`. - Refer to the [Gmail OAuth2 Credentials Documentation](./docs/Gmail_Credentials_OAuth2.md) for details on obtaining credentials. - Run the `gExampleOauth2()` function to send a test email. #### 4. Microsoft 365 Email Sender -- Configure your Microsoft Graph API credentials in `providers/microsoft365_email_sender.go`. +- Configure your Microsoft Graph API credentials in `providers/microsoft365/microsoft365_email_sender.go`. - Refer to the [Microsoft 365 Credentials Documentation](./docs/Microsoft365_Credentials_ROPC.md) for details on obtaining credentials. - Run the `msGraphExample()` function to send a test email. #### 5. SendGrid Email Sender -- Configure your SendGrid API key in `providers/sendgrid_email_sender.go`. +- Configure your SendGrid API key in `providers/sendgrid/sendgrid_email_sender.go`. - Refer to the [SendGrid Credentials Documentation](./docs/SendGrid_Credentials.md) for details on obtaining credentials. - Run the `sendgridExample()` function to send a test email. #### 6. AWS SES Email Sender -- Configure your AWS SES credentials in `providers/ses_email_sender.go`. +- Configure your AWS SES credentials in `providers/ses/ses_email_sender.go`. - Refer to the [AWS SES Credentials Documentation](./docs/AWS_SES_Credentials.md) for details on obtaining credentials. - Run the `sesExample()` function to send a test email. #### 7. Mailgun Email Sender -- Configure your Mailgun API key in `providers/mailgun_email_sender.go`. +- Configure your Mailgun API key in `providers/mailgun/mailgun_email_sender.go`. - Refer to the [Mailgun Credentials Documentation](./docs/Mailgun_Credentials.md) for details on obtaining credentials. - Run the `mailgunExample()` function to send a test email. #### 8. Mandrill Email Sender -- Configure your Mandrill API key in `providers/mandrill_email_sender.go`. +- Configure your Mandrill API key in `providers/mandrill/mandrill_email_sender.go`. - Refer to the [Mandrill Credentials Documentation](./docs/Mandrill_Credentials.md) for details on obtaining credentials. - Run the `mandrillExample()` function to send a test email. #### 9. Postmark Email Sender -- Configure your Postmark API key in `providers/postmark_email_sender.go`. +- Configure your Postmark API key in `providers/postmark/postmark_email_sender.go`. - Refer to the [Postmark Credentials Documentation](./docs/Postmark_Credentials.md) for details on obtaining credentials. - Run the `postmarkExample()` function to send a test email. #### 10. SparkPost Email Sender -- Configure your SparkPost API key in `providers/sparkpost_email_sender.go`. +- Configure your SparkPost API key in `providers/sparkpost/sparkpost_email_sender.go`. - Refer to the [SparkPost Documentation](https://developers.sparkpost.com/api/) for details on obtaining credentials. - Run the `sparkpostExample()` function to send a test email. diff --git a/docs/Gmail_Credentials_API_Key.md b/docs/Gmail_Credentials_API_Key.md index 522b8d1..78b1193 100644 --- a/docs/Gmail_Credentials_API_Key.md +++ b/docs/Gmail_Credentials_API_Key.md @@ -31,7 +31,7 @@ apiKey := "your-api-key" user := "me" // Initialize the GmailEmailSender -emailSender, err := providers.NewGmailEmailSenderAPIKey(apiKey, user) +emailSender, err := gmail.NewGmailEmailSenderAPIKey(apiKey, user) if err != nil { log.Fatalf("Failed to create GmailEmailSender: %v", err) } diff --git a/docs/Gmail_Credentials_JWT.md b/docs/Gmail_Credentials_JWT.md index ba8af6a..1f706db 100644 --- a/docs/Gmail_Credentials_JWT.md +++ b/docs/Gmail_Credentials_JWT.md @@ -71,7 +71,7 @@ jsonCredentials := []byte(`{ user := "user@domain.com" // Initialize the GmailEmailSender -emailSender, err := providers.NewGmailEmailSenderJWT(jsonCredentials, user) +emailSender, err := gmail.NewGmailEmailSenderJWT(jsonCredentials, user) if err != nil { log.Fatalf("Failed to create GmailEmailSender: %v", err) } diff --git a/docs/Gmail_Credentials_OAuth2.md b/docs/Gmail_Credentials_OAuth2.md index 3bf7723..ac2d7ca 100644 --- a/docs/Gmail_Credentials_OAuth2.md +++ b/docs/Gmail_Credentials_OAuth2.md @@ -17,7 +17,7 @@ jsonCredentials := []byte(`{ user := "user@domain.com" // Initialize the GmailEmailSender -emailSender, err := providers.NewGmailEmailSenderServiceAccount(jsonCredentials, user) +emailSender, err := gmail.NewGmailEmailSenderServiceAccount(jsonCredentials, user) if err != nil { log.Fatalf("Failed to create GmailEmailSender: %v", err) } @@ -131,7 +131,7 @@ tokenManager := &MyTokenManager{ } // Create GmailEmailSender with the parsed credentials and token -emailSender, err := providers.NewGmailEmailSenderOauth2(credentials, tokenManager, "me") +emailSender, err := gmail.NewGmailEmailSenderOauth2(credentials, tokenManager, "me") if err != nil { log.Fatalf("Failed to create email sender: %v", err) } diff --git a/docs/Gmail_Credentials_ServiceAccount copy.md b/docs/Gmail_Credentials_ServiceAccount copy.md index 27fffb6..0627796 100644 --- a/docs/Gmail_Credentials_ServiceAccount copy.md +++ b/docs/Gmail_Credentials_ServiceAccount copy.md @@ -72,7 +72,7 @@ jsonCredentials := []byte(`{ user := "user@domain.com" // Initialize the GmailEmailSender -emailSender, err := providers.NewGmailEmailSenderJWTAccess(jsonCredentials, user) +emailSender, err := gmail.NewGmailEmailSenderJWTAccess(jsonCredentials, user) if err != nil { log.Fatalf("Failed to create GmailEmailSender: %v", err) } diff --git a/docs/Gmail_Credentials_ServiceAccount.md b/docs/Gmail_Credentials_ServiceAccount.md index aa5e192..e6cbbea 100644 --- a/docs/Gmail_Credentials_ServiceAccount.md +++ b/docs/Gmail_Credentials_ServiceAccount.md @@ -65,7 +65,7 @@ jsonCredentials := []byte(`{ user := "user@domain.com" // Initialize the GmailEmailSender -emailSender, err := providers.NewGmailEmailSenderServiceAccount(jsonCredentials, user) +emailSender, err := gmail.NewGmailEmailSenderServiceAccount(jsonCredentials, user) if err != nil { log.Fatalf("Failed to create GmailEmailSender: %v", err) } diff --git a/docs/SMTP_Credentials.md b/docs/SMTP_Credentials.md index bc05ac7..0830fbb 100644 --- a/docs/SMTP_Credentials.md +++ b/docs/SMTP_Credentials.md @@ -29,7 +29,7 @@ password := "your-password" authMethod := AUTH_PLAIN // Create SmtpEmailSender with the SMTP server settings -emailSender, _ := providers.NewSmtpEmailSender( +emailSender, _ := gmail.NewSmtpEmailSender( host, port, user, diff --git a/email_sender.go b/email_sender.go index fd0718f..febc3ee 100644 --- a/email_sender.go +++ b/email_sender.go @@ -9,6 +9,7 @@ // This project is organized into several packages: // // - providers: Contains implementations for various email providers. +// - credentials: Contains implementations for managing email credentials. // - examples: Contains example applications demonstrating how to use the library. // - docs: Contains documentation for configuring different email providers. // @@ -22,12 +23,12 @@ // package main // // import ( -// "github.com/darkrockmountain/gomail/providers" +// "github.com/darkrockmountain/gomail/providers/sendgrid" // ) // // func main() { -// sender := providers.NewSendGridEmailSender("your-api-key") -// err := sender.SendEmail("recipient@example.com", "Subject", "Email body") +// sender := sendgrid.NewSendGridEmailSender("your-api-key") +// err := sender.SendEmail(EmailMessage{To:[]string{"recipient@example.com"}, Subject:"Subject", Text:"Email body"}) // if err != nil { // log.Fatal(err) // } diff --git a/providers/doc.go b/providers/doc.go index b273cf4..784c58f 100644 --- a/providers/doc.go +++ b/providers/doc.go @@ -17,11 +17,12 @@ // // import ( // "github.com/darkrockmountain/gomail" +// "github.com/darkrockmountain/gomail/providers/sendgrid" // ) // // func main() { -// sender := providers.NewSendGridEmailSender("your-api-key") -// err := sender.SendEmail("recipient@example.com", "Subject", "Email body") +// sender := sendgrid.NewSendGridEmailSender("your-api-key") +// err := sender.SendEmail(EmailMessage{To:[]string{"recipient@example.com"}, Subject:"Subject", Text:"Email body"}) // if err != nil { // log.Fatal(err) // }