Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IMailClient ¶
type IMailClient interface {
// MailUsr returns the username of the mail client.
MailUsr() string
// CreateTextMessage creates a new plain text mail message.
CreateTextMessage() IMailMessage
// CreateHtmlMessage creates a new HTML mail message.
CreateHtmlMessage() IMailMessage
// CreateJsonMessage creates a new JSON mail message.
CreateJsonMessage() IMailMessage
// CreateTemplateMessage creates a new mail message from a template.
CreateTemplateMessage(template TemplateName, variables map[string]string) IMailMessage
}
IMailClient defines the interface for a mail client, which is responsible for creating and sending messages.
func NewMailClient ¶
func NewMailClient(config MailConfig) (IMailClient, error)
NewMailClient is a factory function that creates a new mail client based on the provided configuration.
type IMailMessage ¶
type IMailMessage interface {
From(from string) IMailMessage
To(to []string) IMailMessage
Cc(cc []string) IMailMessage
Bcc(bcc []string) IMailMessage
Subject(subject string) IMailMessage
Body(body string) IMailMessage
HtmlBody(html string) IMailMessage
Attachments(attachments []MailMessageAttachment) IMailMessage
AddTo(to ...string) IMailMessage
AddCc(cc ...string) IMailMessage
AddBcc(bcc ...string) IMailMessage
AddAttachments(attachments ...MailMessageAttachment) IMailMessage
Attach(paths ...string) IMailMessage
Send() error
}
IMailMessage defines the interface for a mail message, providing methods to build and send the message.
type MailConfig ¶
type MailConfig struct {
// MailRelayUri is the URI of the mail relay, e.g., "smtp://smtp.example.com:587" or "https://api.mailgun.net/v3".
MailRelayUri string
// MailRelayUser is the username for authentication with the mail relay.
MailRelayUser string
// MailRelayPassword is the password for authentication with the mail relay.
MailRelayPassword string
// UseTLS specifies whether to use TLS for the connection. This is primarily for SMTP.
UseTLS bool
// Headers is a map of HTTP headers to be sent with the request, applicable for HTTP-based mail clients.
Headers map[string]string
}
MailConfig holds the configuration for creating a mail client. It uses a fluent API to set the configuration parameters.
func NewMailConfig ¶ added in v1.2.146
func NewMailConfig(uri string) *MailConfig
NewMailConfig creates a new MailConfig with the given URI.
Parameters:
uri: The URI of the mail relay.
Returns:
A new MailConfig instance.
func (*MailConfig) CreateClient ¶ added in v1.2.146
func (mc *MailConfig) CreateClient() (IMailClient, error)
CreateClient creates a mail client based on the configuration. It determines the client type (SMTP or HTTP) from the URI scheme.
Returns:
An IMailClient instance. An error if the URI is invalid or the scheme is unsupported.
func (*MailConfig) SetHeader ¶ added in v1.2.146
func (mc *MailConfig) SetHeader(header, value string) *MailConfig
SetHeader sets an HTTP header for HTTP-based mail clients.
Parameters:
header: The name of the header. value: The value of the header.
Returns:
The MailConfig instance for chaining.
func (*MailConfig) WithPassword ¶ added in v1.2.146
func (mc *MailConfig) WithPassword(value string) *MailConfig
WithPassword sets the mail relay password.
Parameters:
value: The password.
Returns:
The MailConfig instance for chaining.
func (*MailConfig) WithTLS ¶ added in v1.2.146
func (mc *MailConfig) WithTLS(value bool) *MailConfig
WithTLS sets the TLS flag.
Parameters:
value: The TLS flag.
Returns:
The MailConfig instance for chaining.
func (*MailConfig) WithUser ¶ added in v1.2.146
func (mc *MailConfig) WithUser(value string) *MailConfig
WithUser sets the mail relay username.
Parameters:
value: The username.
Returns:
The MailConfig instance for chaining.
type MailMessageAttachment ¶
type MailMessageAttachment struct {
// FileName is the name of the file to be attached.
FileName string `json:"fileName"`
// Content is the base64-encoded content of the file.
Content string `json:"content"`
// ContentType is the MIME type of the attachment. For base64 content, it should include ";base64".
ContentType string `json:"contentType"`
}
MailMessageAttachment represents a file attached to an email.
type TemplateName ¶
type TemplateName string
TemplateName is a type alias for a string, representing the name of a mail template.