package carrier
import "petersanchez.com/carrier"
Package carrier implements sending email via various services with a single message object.
This package will panic if you pass in email addresses that are invalid. Please be sure to validate your input before passing it in.
ExampleΒΆ
Code:
svc := carrier.NewConsoleService() msg := carrier.NewMessage() msg.SetFrom("me@mydomain.com"). SetTo("recipient@theirdomain.com"). SetCc("copy@somedomain.com") msg.SetSubject("Sending email from Go!") // You should handle errors properly in all instances below file, err := os.Open("funny.jpg") if err != nil { log.Fatal(err) } msg.AddAttachment("funny.jpg", file, "") file.Close() err = msg.SetBody("This is the text email body.") err = msg.SetBodyHTML("This is the HTML email body.") // Send email err = svc.Send(msg) log.Println("Successfully sent email.")
Index ¶
- func SendMail(to string, from string, subject string, text string, html string, svc Service) error
- type ConsoleService
- type Message
- func NewMessage() *Message
- func (m *Message) AddAttachment(filename string, data io.Reader, ctype string) error
- func (m *Message) Buffer() *bytes.Buffer
- func (m *Message) Bytes() []byte
- func (m *Message) Close()
- func (m *Message) GetAllRcpts() []string
- func (m *Message) SendMail(svc Service) error
- func (m *Message) SetBcc(address string) *Message
- func (m *Message) SetBccCSV(address string) *Message
- func (m *Message) SetBccList(addresses []string) *Message
- func (m *Message) SetBody(body string) error
- func (m *Message) SetBodyHTML(body string) error
- func (m *Message) SetCc(address string) *Message
- func (m *Message) SetCcCSV(address string) *Message
- func (m *Message) SetCcList(addresses []string) *Message
- func (m *Message) SetFrom(address string) *Message
- func (m *Message) SetHTML(msg io.Reader) error
- func (m *Message) SetText(msg io.Reader) error
- func (m *Message) SetTo(address string) *Message
- func (m *Message) SetToCSV(address string) *Message
- func (m *Message) SetToList(addresses []string) *Message
- func (m *Message) String() string
- type Service
Examples ¶
Package Files ¶
carrier.go console.go message.go send.go
func SendMail ¶
SendMail is a quick helper to send out an email using a given service
type ConsoleService ¶
type ConsoleService struct {
// contains filtered or unexported fields
}
ConsoleService is a simple email service to print email to the set writer
func NewConsoleService ¶
func NewConsoleService() *ConsoleService
NewConsoleService returns an smtp service instance
func (*ConsoleService) Send ¶
func (c *ConsoleService) Send(msg *Message) error
Send match email Service interface signature
type Message ¶
Message object which holds the entire email message. Each service will take a *Message object and use it to parse out the required data to send the email.
func NewMessage ¶
func NewMessage() *Message
NewMessage returns a new *Message object
func (*Message) AddAttachment ¶
AddAttachment Adds an attachment to the message. If ctype is blank the func will try to guess the content-type
func (*Message) Buffer ¶
Buffer Returns the raw email buffer
func (*Message) Bytes ¶
Bytes Returns full email as bytes
func (*Message) Close ¶
func (m *Message) Close()
Close Closes the mail.Writer
func (*Message) GetAllRcpts ¶
GetAllRcpts Returns all email recipients
func (*Message) SendMail ¶
SendMail Sends the message as an email via the given service.
func (*Message) SetBcc ¶
SetBcc Set the Bcc: header
func (*Message) SetBccCSV ¶
SetBccCSV Set Bcc: header. See SetToCSV comment
func (*Message) SetBccList ¶
SetBccList Set the Bcc: header to multiple addresses
func (*Message) SetBody ¶
SetBody Set the text/plain part of the email
func (*Message) SetBodyHTML ¶
SetBodyHTML Set the text/html part of the email
func (*Message) SetCc ¶
SetCc Set the Cc: header
func (*Message) SetCcCSV ¶
SetCcCSV Set Cc: header. See SetToCSV comment.
func (*Message) SetCcList ¶
SetCcList Set the Cc: address header to multiple addresses
func (*Message) SetFrom ¶
SetFrom Set the From: header
func (*Message) SetHTML ¶
SetHTML Set the text/html part of the email, via io.Reader instance
func (*Message) SetText ¶
SetText Set the text/plain part of the email, via io.Reader instance
func (*Message) SetTo ¶
SetTo Set the To: header
func (*Message) SetToCSV ¶
SetToCSV Set the To: header from a comma separated list of emails. Ie, user1@foobar.com, user2@foobar.com, etc.
func (*Message) SetToList ¶
SetToList Set the To: header to multiple addresses
func (*Message) String ¶
String Returns full email as string
type Service ¶
Service interface
- Version
- v0.1.0 (latest)
- Published
- Feb 3, 2022
- Platform
- linux/amd64
- Imports
- 10 packages (graph)
- Last checked
- 6 days ago –
Tools for package owners.