email

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 5, 2025 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithAttachments

func WithAttachments(attachments []string) func(*Mailer)

WithAttachments sets the attachments (Option pattern). WithAttachments 设置附件(Option 模式)。

Parameters: 参数: - attachments: List of attachment file paths (附件文件路径列表)

func WithBcc

func WithBcc(bcc []string) func(*Mailer)

WithBcc sets the BCC recipients (Option pattern). WithBcc 设置密送(Option 模式)。

Parameters: 参数: - bcc: List of BCC email addresses (密送邮箱地址列表)

func WithBody

func WithBody(body string) func(*Mailer)

WithBody sets the plain text body (Option pattern). WithBody 设置纯文本正文(Option 模式)。

Parameters: 参数: - body: Plain text body (纯文本正文)

func WithCc

func WithCc(cc []string) func(*Mailer)

WithCc sets the CC recipients (Option pattern). WithCc 设置抄送(Option 模式)。

Parameters: 参数: - cc: List of CC email addresses (抄送邮箱地址列表)

func WithFrom

func WithFrom(from, alias string) func(*Mailer)

WithFrom sets the sender (Option pattern). WithFrom 设置发件人(Option 模式)。

Parameters: 参数: - from: Sender email address (发件人邮箱地址) - alias: Sender alias (发件人别名)

func WithHTMLBody

func WithHTMLBody(htmlBody string) func(*Mailer)

WithHTMLBody sets the HTML body (Option pattern). WithHTMLBody 设置 HTML 正文(Option 模式)。

Parameters: 参数: - htmlBody: HTML body (HTML 正文)

func WithInlineImages

func WithInlineImages(images map[string]string) func(*Mailer)

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

func WithSMTPConfig(host, port, user, password string) func(*Mailer)

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

func WithSSL(useSSL bool) func(*Mailer)

WithSSL sets whether to use SSL (Option pattern). WithSSL 设置是否使用 SSL(Option 模式)。

Parameters: 参数: - useSSL: Whether to use SSL (是否使用 SSL)

func WithSubject

func WithSubject(subject string) func(*Mailer)

WithSubject sets the email subject (Option pattern). WithSubject 设置邮件主题(Option 模式)。

Parameters: 参数: - subject: Email subject (邮件主题)

func WithTo

func WithTo(to []string) func(*Mailer)

WithTo sets the recipients (Option pattern). WithTo 设置收件人(Option 模式)。

Parameters: 参数: - to: List of recipient email addresses (收件人邮箱地址列表)

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

func NewMailer(options ...func(*Mailer)) *Mailer

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

func (mailer *Mailer) Send() error

Send sends the email. Send 发送邮件。

Returns: 返回值: - error: Returns an error if sending fails. (如果发送失败,返回错误信息)

func (*Mailer) SetAttachments

func (mailer *Mailer) SetAttachments(attachments []string) *Mailer

SetAttachments sets the attachments (Fluent interface). SetAttachments 设置附件(链式调用模式)。

Parameters: 参数: - attachments: List of attachment file paths (附件文件路径列表)

func (*Mailer) SetBcc

func (mailer *Mailer) SetBcc(bcc []string) *Mailer

SetBcc sets the BCC recipients (Fluent interface). SetBcc 设置密送(链式调用模式)。

Parameters: 参数: - bcc: List of BCC email addresses (密送邮箱地址列表)

func (*Mailer) SetBody

func (mailer *Mailer) SetBody(body string) *Mailer

SetBody sets the plain text body (Fluent interface). SetBody 设置纯文本正文(链式调用模式)。

Parameters: 参数: - body: Plain text body (纯文本正文)

func (*Mailer) SetCc

func (mailer *Mailer) SetCc(cc []string) *Mailer

SetCc sets the CC recipients (Fluent interface). SetCc 设置抄送(链式调用模式)。

Parameters: 参数: - cc: List of CC email addresses (抄送邮箱地址列表)

func (*Mailer) SetFrom

func (mailer *Mailer) SetFrom(from, alias string) *Mailer

SetFrom sets the sender (Fluent interface). SetFrom 设置发件人(链式调用模式)。

Parameters: 参数: - from: Sender email address (发件人邮箱地址) - alias: Sender alias (发件人别名)

func (*Mailer) SetHTMLBody

func (mailer *Mailer) SetHTMLBody(htmlBody string) *Mailer

SetHTMLBody sets the HTML body (Fluent interface). SetHTMLBody 设置 HTML 正文(链式调用模式)。

Parameters: 参数: - htmlBody: HTML body (HTML 正文)

func (*Mailer) SetInlineImages

func (mailer *Mailer) SetInlineImages(images map[string]string) *Mailer

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

func (mailer *Mailer) SetSMTPConfig(host, port, user, password string) *Mailer

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

func (mailer *Mailer) SetSSL(useSSL bool) *Mailer

SetSSL sets whether to use SSL (Fluent interface). SetSSL 设置是否使用 SSL(链式调用模式)。

Parameters: 参数: - useSSL: Whether to use SSL (是否使用 SSL)

func (*Mailer) SetSubject

func (mailer *Mailer) SetSubject(subject string) *Mailer

SetSubject sets the email subject (Fluent interface). SetSubject 设置邮件主题(链式调用模式)。

Parameters: 参数: - subject: Email subject (邮件主题)

func (*Mailer) SetTo

func (mailer *Mailer) SetTo(to []string) *Mailer

SetTo sets the recipients (Fluent interface). SetTo 设置收件人(链式调用模式)。

Parameters: 参数: - to: List of recipient email addresses (收件人邮箱地址列表)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL