Documentation
¶
Index ¶
- func WithAttachments(attachments []string) func(*Mailer)
- func WithBcc(bcc []string) func(*Mailer)
- func WithBody(body string) func(*Mailer)
- func WithCc(cc []string) func(*Mailer)
- func WithFrom(from, alias string) func(*Mailer)
- func WithHTMLBody(htmlBody string) func(*Mailer)
- func WithInlineImages(images map[string]string) func(*Mailer)
- func WithSMTPConfig(host, port, user, password string) func(*Mailer)
- func WithSSL(useSSL bool) func(*Mailer)
- func WithSubject(subject string) func(*Mailer)
- func WithTo(to []string) func(*Mailer)
- type Mailer
- func (mailer *Mailer) Send() error
- func (mailer *Mailer) SetAttachments(attachments []string) *Mailer
- func (mailer *Mailer) SetBcc(bcc []string) *Mailer
- func (mailer *Mailer) SetBody(body string) *Mailer
- func (mailer *Mailer) SetCc(cc []string) *Mailer
- func (mailer *Mailer) SetFrom(from, alias string) *Mailer
- func (mailer *Mailer) SetHTMLBody(htmlBody string) *Mailer
- func (mailer *Mailer) SetInlineImages(images map[string]string) *Mailer
- func (mailer *Mailer) SetSMTPConfig(host, port, user, password string) *Mailer
- func (mailer *Mailer) SetSSL(useSSL bool) *Mailer
- func (mailer *Mailer) SetSubject(subject string) *Mailer
- func (mailer *Mailer) SetTo(to []string) *Mailer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithAttachments ¶
WithAttachments sets the attachments (Option pattern). WithAttachments 设置附件(Option 模式)。
Parameters: 参数: - attachments: List of attachment file paths (附件文件路径列表)
func WithBcc ¶
WithBcc sets the BCC recipients (Option pattern). WithBcc 设置密送(Option 模式)。
Parameters: 参数: - bcc: List of BCC email addresses (密送邮箱地址列表)
func WithBody ¶
WithBody sets the plain text body (Option pattern). WithBody 设置纯文本正文(Option 模式)。
Parameters: 参数: - body: Plain text body (纯文本正文)
func WithCc ¶
WithCc sets the CC recipients (Option pattern). WithCc 设置抄送(Option 模式)。
Parameters: 参数: - cc: List of CC email addresses (抄送邮箱地址列表)
func WithFrom ¶
WithFrom sets the sender (Option pattern). WithFrom 设置发件人(Option 模式)。
Parameters: 参数: - from: Sender email address (发件人邮箱地址) - alias: Sender alias (发件人别名)
func WithHTMLBody ¶
WithHTMLBody sets the HTML body (Option pattern). WithHTMLBody 设置 HTML 正文(Option 模式)。
Parameters: 参数: - htmlBody: HTML body (HTML 正文)
func WithInlineImages ¶
WithInlineImages sets the inline images (Option pattern). WithInlineImages 设置内嵌图片(Option 模式)。
Parameters: 参数: - images: Map of inline images, key is Content-ID, value is file path (内嵌图片映射,key 为 Content-ID,value 为文件路径)
func WithSMTPConfig ¶
WithSMTPConfig sets the SMTP configuration (Option pattern). WithSMTPConfig 设置 SMTP 配置(Option 模式)。
Parameters: 参数: - host: SMTP server address (SMTP 服务器地址) - port: SMTP server port (SMTP 服务器端口) - user: Email account (邮箱账号) - password: Email password (邮箱密码)
func WithSSL ¶
WithSSL sets whether to use SSL (Option pattern). WithSSL 设置是否使用 SSL(Option 模式)。
Parameters: 参数: - useSSL: Whether to use SSL (是否使用 SSL)
func WithSubject ¶
WithSubject sets the email subject (Option pattern). WithSubject 设置邮件主题(Option 模式)。
Parameters: 参数: - subject: Email subject (邮件主题)
Types ¶
type Mailer ¶
type Mailer struct { SMTPHost string // SMTP server address (SMTP 服务器地址) SMTPPort string // SMTP server port (SMTP 服务器端口) SMTPUser string // Email account (邮箱账号) SMTPPassword string // Email password (邮箱密码) From string // Sender email address (发件人邮箱地址) FromAlias string // Sender alias (发件人别名) To []string // List of recipient email addresses (收件人邮箱地址列表) Cc []string // List of CC email addresses (抄送邮箱地址列表) Bcc []string // List of BCC email addresses (密送邮箱地址列表) Subject string // Email subject (邮件主题) Body string // Plain text body (纯文本正文) HTMLBody string // HTML body (HTML 正文) Attachments []string // List of attachment file paths (附件文件路径列表) InlineImages map[string]string // Inline images: key is Content-ID, value is file path (内嵌图片:key 为 Content-ID,value 为文件路径) UseSSL bool // Whether to use SSL (是否使用 SSL) }
Mailer represents an email client for sending emails. Mailer 表示用于发送邮件的邮件客户端。
func NewMailer ¶
NewMailer creates a new Mailer with optional configurations. NewMailer 创建一个新的 Mailer,支持可选配置。
Example (Option pattern): 示例(Option 模式): mailer := NewMailer(
WithSMTPConfig("smtp.example.com", "465", "your-email@example.com", "your-password"), WithFrom("your-email@example.com", "Your Name"), WithTo([]string{"recipient1@example.com", "recipient2@example.com"}), WithCc([]string{"cc@example.com"}), WithBcc([]string{"bcc@example.com"}), WithSubject("Test Email"), WithBody("This is a plain text email."), WithHTMLBody("<html><body><h1>This is an HTML email</h1></body></html>"), WithAttachments([]string{"./file1.txt", "./file2.txt"}), WithInlineImages(map[string]string{"image1": "./image.jpg"}), WithSSL(true),
)
Example (Fluent interface): 示例(链式调用模式): mailer := NewMailer().
SetFrom("your-email@example.com", "Your Name"). SetTo([]string{"recipient1@example.com", "recipient2@example.com"}). SetCc([]string{"cc@example.com"}). SetBcc([]string{"bcc@example.com"}). SetSubject("Test Email"). SetBody("This is a plain text email."). SetHTMLBody("<html><body><h1>This is an HTML email</h1></body></html>"). SetAttachments([]string{"./file1.txt", "./file2.txt"}). SetInlineImages(map[string]string{"image1": "./image.jpg"}). SetSSL(true)
func (*Mailer) Send ¶
Send sends the email. Send 发送邮件。
Returns: 返回值: - error: Returns an error if sending fails. (如果发送失败,返回错误信息)
func (*Mailer) SetAttachments ¶
SetAttachments sets the attachments (Fluent interface). SetAttachments 设置附件(链式调用模式)。
Parameters: 参数: - attachments: List of attachment file paths (附件文件路径列表)
func (*Mailer) SetBcc ¶
SetBcc sets the BCC recipients (Fluent interface). SetBcc 设置密送(链式调用模式)。
Parameters: 参数: - bcc: List of BCC email addresses (密送邮箱地址列表)
func (*Mailer) SetBody ¶
SetBody sets the plain text body (Fluent interface). SetBody 设置纯文本正文(链式调用模式)。
Parameters: 参数: - body: Plain text body (纯文本正文)
func (*Mailer) SetCc ¶
SetCc sets the CC recipients (Fluent interface). SetCc 设置抄送(链式调用模式)。
Parameters: 参数: - cc: List of CC email addresses (抄送邮箱地址列表)
func (*Mailer) SetFrom ¶
SetFrom sets the sender (Fluent interface). SetFrom 设置发件人(链式调用模式)。
Parameters: 参数: - from: Sender email address (发件人邮箱地址) - alias: Sender alias (发件人别名)
func (*Mailer) SetHTMLBody ¶
SetHTMLBody sets the HTML body (Fluent interface). SetHTMLBody 设置 HTML 正文(链式调用模式)。
Parameters: 参数: - htmlBody: HTML body (HTML 正文)
func (*Mailer) SetInlineImages ¶
SetInlineImages sets the inline images (Fluent interface). SetInlineImages 设置内嵌图片(链式调用模式)。
Parameters: 参数: - images: Map of inline images, key is Content-ID, value is file path (内嵌图片映射,key 为 Content-ID,value 为文件路径)
func (*Mailer) SetSMTPConfig ¶
SetSMTPConfig sets the SMTP configuration (Fluent interface). SetSMTPConfig 设置 SMTP 配置(链式调用模式)。
Parameters: 参数: - host: SMTP server address (SMTP 服务器地址) - port: SMTP server port (SMTP 服务器端口) - user: Email account (邮箱账号) - password: Email password (邮箱密码)
func (*Mailer) SetSSL ¶
SetSSL sets whether to use SSL (Fluent interface). SetSSL 设置是否使用 SSL(链式调用模式)。
Parameters: 参数: - useSSL: Whether to use SSL (是否使用 SSL)
func (*Mailer) SetSubject ¶
SetSubject sets the email subject (Fluent interface). SetSubject 设置邮件主题(链式调用模式)。
Parameters: 参数: - subject: Email subject (邮件主题)