mail

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attachment

type Attachment struct {
	Filename    string
	ContentType string
	Content     []byte
}

Attachment 附件结构

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client 邮件客户端

func NewClientWithConfig

func NewClientWithConfig(config *Config) *Client

NewClientWithConfig 通过配置创建邮件客户端

func (*Client) DeleteMessagePOP3

func (c *Client) DeleteMessagePOP3(messageID int) error

DeleteMessagePOP3 通过POP3删除邮件

func (*Client) GetUnreadCountIMAP

func (c *Client) GetUnreadCountIMAP(folder string) (int, error)

GetUnreadCountIMAP 获取未读邮件数量

func (*Client) ReceiveIMAP

func (c *Client) ReceiveIMAP(folder string, maxMessages int) ([]*Email, error)

ReceiveIMAP 通过IMAP接收邮件

func (*Client) ReceivePOP3

func (c *Client) ReceivePOP3(maxMessages int) ([]*Email, error)

ReceivePOP3 通过POP3接收邮件

func (*Client) Send

func (c *Client) Send(email *Email) error

Send 发送邮件(至少尝试一次,maxRetries 为额外重试次数)

func (*Client) SetAuth

func (c *Client) SetAuth(username, password string) *Client

SetAuth 设置认证信息

func (*Client) SetAuthType

func (c *Client) SetAuthType(authType string) *Client

SetAuthType 设置认证类型

func (*Client) SetIMAP

func (c *Client) SetIMAP(host string, port int) *Client

SetIMAP 设置IMAP服务器

func (*Client) SetPOP3

func (c *Client) SetPOP3(host string, port int) *Client

SetPOP3 设置POP3服务器

func (*Client) SetRetry

func (c *Client) SetRetry(maxRetries int, retryInterval time.Duration) *Client

SetRetry 设置重试参数

func (*Client) SetSMTP

func (c *Client) SetSMTP(host string, port int) *Client

SetSMTP 设置SMTP服务器

func (*Client) SetTLS

func (c *Client) SetTLS(useTLS bool) *Client

SetTLS 设置是否使用TLS

func (*Client) SetTimeout

func (c *Client) SetTimeout(timeout time.Duration) *Client

SetTimeout 设置超时时间

type Config

type Config struct {
	SMTPHost      string        `yaml:"smtp_host" json:"smtp_host"`
	SMTPPort      int           `yaml:"smtp_port" json:"smtp_port"`
	POP3Host      string        `yaml:"pop3_host" json:"pop3_host"`
	POP3Port      int           `yaml:"pop3_port" json:"pop3_port"`
	IMAPHost      string        `yaml:"imap_host" json:"imap_host"`
	IMAPPort      int           `yaml:"imap_port" json:"imap_port"`
	Username      string        `yaml:"username" json:"username"`
	Password      string        `yaml:"password" json:"password"`
	UseTLS        bool          `yaml:"use_tls" json:"use_tls"`
	AuthType      string        `yaml:"auth_type" json:"auth_type"` // "plain", "login", "cram-md5"
	Timeout       time.Duration `yaml:"timeout" json:"timeout"`
	MaxRetries    int           `yaml:"max_retries" json:"max_retries"`
	RetryInterval time.Duration `yaml:"retry_interval" json:"retry_interval"`
}

Config 邮件客户端配置

func NewConfig

func NewConfig(smtpHost string, smtpPort int, pop3Host string, pop3Port int, imapHost string, imapPort int, username, password string, useTLS bool, authType string, timeout time.Duration, maxRetries int, retryInterval time.Duration) *Config

NewConfig 创建新的邮件客户端配置

type Email

type Email struct {
	From        string
	To          []string
	Cc          []string
	Bcc         []string
	Subject     string
	Body        string
	HTMLBody    string
	Attachments []Attachment
	Headers     map[string]string
	SentAt      time.Time
}

Email 邮件结构

func NewEmail

func NewEmail() *Email

NewEmail 创建新邮件

func ParseMIME

func ParseMIME(data []byte) (*Email, error)

ParseMIME 从MIME格式解析邮件

func (*Email) AddAttachment

func (e *Email) AddAttachment(filename, contentType string, content []byte) *Email

AddAttachment 添加附件

func (*Email) AddAttachmentFromFile

func (e *Email) AddAttachmentFromFile(filePath string) error

AddAttachmentFromFile 从文件添加附件

func (*Email) AddBcc

func (e *Email) AddBcc(bcc ...string) *Email

AddBcc 添加密送

func (*Email) AddCc

func (e *Email) AddCc(cc ...string) *Email

AddCc 添加抄送

func (*Email) AddHeader

func (e *Email) AddHeader(key, value string) *Email

AddHeader 添加自定义头部

func (*Email) AddTo

func (e *Email) AddTo(to ...string) *Email

AddTo 添加收件人

func (*Email) SetBody

func (e *Email) SetBody(body string) *Email

SetBody 设置文本正文

func (*Email) SetFrom

func (e *Email) SetFrom(from string) *Email

SetFrom 设置发件人

func (*Email) SetHTMLBody

func (e *Email) SetHTMLBody(htmlBody string) *Email

SetHTMLBody 设置HTML正文

func (*Email) SetSentAt

func (e *Email) SetSentAt(sentAt time.Time) *Email

SetSentAt 设置发送时间

func (*Email) SetSubject

func (e *Email) SetSubject(subject string) *Email

SetSubject 设置主题

func (*Email) ToMIME

func (e *Email) ToMIME() ([]byte, error)

ToMIME 将邮件转换为MIME格式

Jump to

Keyboard shortcuts

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