smtp.go - Overview
-
Overview This file defines an SMTP service for sending emails. It includes a struct
SMTP
to hold SMTP server configuration and methods to initialize the configuration and send emails. -
Detailed Documentation
SMTP
- Purpose: Represents the SMTP server configuration.
- Fields:
Host
(string): The SMTP server host.Port
(string): The SMTP server port.Username
(string): The SMTP server username.Password
(string): The SMTP server password.From
(string): The sender's email address.
New
- Purpose: Creates a new
SMTP
instance by reading configuration from environment variables. - Returns:
*SMTP
: A pointer to the newSMTP
instance.
GetInstance
- Purpose: Returns a singleton instance of the
SMTP
struct. It ensures that only one instance is created. - Returns:
*SMTP
: A pointer to the singletonSMTP
instance.
SendEmail
- Purpose: Sends an email using the SMTP configuration.
- Parameters:
to
(string): The recipient's email address (or comma-separated list of addresses).subject
(string): The email subject.body
(string): The email body (HTML content).
- Returns:
error
: An error if the email fails to send, nil otherwise.
- Code Examples
None
- Clarity and Accuracy
The documentation is based solely on the code provided.
- Markdown & MDX Perfection
The markdown syntax is correct.
- Edge Cases To Avoid Breaking MDX
All potential MDX breaking characters are properly escaped or enclosed in code blocks.
- Getting Started Relevance
Include in Getting Started: NO