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" "github.com/darkrockmountain/gomail/providers/sendgrid" ) func main() { sender := sendgrid.NewSendGridEmailSender("your-api-key") err := sender.SendEmail(gomail.NewEmailMessage([]string{"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
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildMimeMessage ¶
func BuildMimeMessage(message *gomail.EmailMessage) ([]byte, error)
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.
Parameters: - message: A pointer to an EmailMessage struct containing the details of the email to be sent.
Returns: - []byte: A byte slice containing the complete MIME message. - error: An error if constructing the MIME message fails, otherwise nil.
Example:
message := gomail.NewEmailMessage( "sender@example.com", []string["recipient@example.com"], "Test Email", "This is a test email.",) .SetHtml("<p>This is a test email.</p>").AddAttachment(Attachment{ Filename: "test.txt", Content: []byte("This is a test attachment."), }) mimeMessage, err := BuildMimeMessage(message) if err != nil { log.Fatalf("Failed to build MIME message: %v", err) } fmt.Println(string(mimeMessage))
func StrPtr ¶
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.
Parameters:
- str (string): The input string value that you want to convert to a pointer.
Returns:
- *string: A pointer to the input string value.
Example usage:
name := "John Doe" 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`. This can be particularly useful in the following scenarios:
- Passing strings by reference to functions, which can help avoid copying large strings.
- Working with data structures that use pointers to represent optional fields or nullable strings.
- Interfacing with APIs or libraries that require or return string pointers.
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.
Types ¶
This section is empty.