Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MakeEmailMessage ¶
MakeEmailMessage creates a composer for emails without a priority set
func MakeSender ¶
func MakeSender(opts *SMTPOptions) (send.Sender, error)
MakeSender constructs an unconfigured (e.g. without level information) SMTP Sender implementation that delivers mail for every loggable message. The configuration of the outgoing SMTP server, and the formatting of the log message is handled by the SMTPOptions structure, which you must use to configure this sender.
Types ¶
type Message ¶
type Message struct { From string `bson:"from" json:"from" yaml:"from"` Recipients []string `bson:"recipients" json:"recipients" yaml:"recipients"` Subject string `bson:"subject" json:"subject" yaml:"subject"` Body string `bson:"body" json:"body" yaml:"body"` // PlainTextContents dictates the Content-Type of the email. If true, // it will text/plain; otherwise, it is text/html. This value is overridden // by the presence of a "Content-Type" header in Headers. PlainTextContents bool `bson:"is_plain_text" json:"is_plain_text" yaml:"is_plain_text"` // Headers adds additional headers to the email body, ignoring any // named "To", "From", "Subject", or "Content-Transfer-Encoding" // (which should be set with the above fields) Headers map[string][]string `bson:"headers" json:"headers" yaml:"headers"` }
Message represents the parameters of an email message
type SMTPOptions ¶
type SMTPOptions struct { // Name controls both the name of the logger, and the name on // the from header field. Name string // From specifies the address specified. From string // Server, Port, and UseSSL control how we connect to the SMTP // server. If unspecified, these options default to // "localhost", port, and false. Server string Port int UseSSL bool // Username and password define how the client authenticates // to the SMTP server. If no Username is specified, the client // will not authenticate to the server. Username string Password string // These options control the output behavior. You must specify // a subject for the emails, *or* one of the bool options that // specify how to generate the subject (e.g. NameAsSubject, // MessageAsSubject) you can specify a non-zero value to // TruncatedMessageSubjectLength to use a fragment of the // message as the subject. The use of these options is // depended on the implementation of the GetContents function. // // The GetContents function returns a pair of strings (subject, // body), and defaults to an implementation that generates a // plain text email according to the (Subject, // TruncatedMessageSubjectLength, NameAsSubject, and // MessageAsSubject). If you use the default GetContents // implementation, PlainTextContents is set to false. // // You can define your own implementation of the GetContents // function, to use a template, or to generate an HTML email // as needed, you must also set PlainTextContents as needed. GetContents func(*SMTPOptions, message.Composer) (string, string) Subject string TruncatedMessageSubjectLength int NameAsSubject bool MessageAsSubject bool PlainTextContents bool // contains filtered or unexported fields }
SMTPOptions configures the behavior of the SMTP logger. There is no explicit constructor; however, the Validate method (which is called by the Sender's constructor) checks for incomplete configuration and sets default options if they are unset.
In additional to constructing this object with the necessary options. You must also set at least one recipient address using the AddRecipient or AddRecipients functions. You can add or reset the recipients after configuring the options or the sender.
func (*SMTPOptions) AddRecipient ¶
func (o *SMTPOptions) AddRecipient(name, address string) error
AddRecipient takes a name and email address as an argument and attempts to parse a valid email address from this data, and if valid adds this email address.
func (*SMTPOptions) AddRecipients ¶
func (o *SMTPOptions) AddRecipients(addresses ...string) error
AddRecipients accepts one or more string that can be, itself, comma separated lists of email addresses, which are then added to the recipients for the logger.
func (*SMTPOptions) ResetRecipients ¶
func (o *SMTPOptions) ResetRecipients()
ResetRecipients removes all recipients from the configuration object. You can reset the recipients at any time, but you must have at least one recipient configured when you use this options object to configure a sender *or* attempt to send a message.
func (*SMTPOptions) Validate ¶
func (o *SMTPOptions) Validate() error
Validate checks the contents of the SMTPOptions struct and sets default values in appropriate cases. Returns an error if the struct is not valid. The constructor for the SMTP sender calls this method to make sure that options struct is valid before initiating the sender.