xmailer

package module
v0.0.0-...-350ba06 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2020 License: MIT Imports: 14 Imported by: 0

README

xmailer

一个简单的邮件客户端,支付二进制附件内容,尤其适合作为Rest API接口服务

usage

html content
import "github.com/longmon/xmailer"

x, err := NewXMailer("smtp.qq.com:587", "abc@qq.com", "xxxxxx")
if err != nil {
    panic(err)
}
m := NewMessage()
m.SetFrom("longmon", "abc@qq.com")
m.SetSubject("Awesome Subject")
m.AddTo("123456789@qq.com")

m.SetHTML("<h1>This is a test email from xmailer</h1>")

err = x.Dial()
if err != nil {
    panic(err)
}

err = x.Send(m)
if err != nil {
    panic(err)
}
with attachment
import "github.com/longmon/xmailer"

x, err := NewXMailer("smtp.qq.com:587", "abc@qq.com", "xxxxxx")
if err != nil {
    panic(err)
}
m := NewMessage()
m.SetFrom("longmon", "abc@qq.com")
m.SetSubject("Awesome Subject")
m.AddTo("123456789@qq.com")

m.SetHTML("<h1>This is a test email from xmailer</h1>")

//附件可以是二进制文件内容
m.AddAttachment(&xmailer.Attachment{
    ContentType: ParseContentTypeWithExt("abc.jpg"),
    BaseName: "abc.jpg",
    Content: []byte(/*file byte data*/)
})
//也可以是本地文件路径,由程序读取二进制内容
//并填充到content
m.AttachFile("/a/b/abc,jpg")

err = x.Dial()
if err != nil {
    panic(err)
}

err = x.Send(m)
if err != nil {
    panic(err)
}

Documentation

Index

Constants

View Source
const LocalName = "localhost"

LocalName 本地主机名

Variables

This section is empty.

Functions

func ParseContentTypeWithExt

func ParseContentTypeWithExt(fileNameWithExt string) string

ParseContentTypeWithExt

Types

type Attachment

type Attachment struct {
	ContentType string
	FileName    string
	BaseName    string
	Content     []byte
}

Attachment 附件对象

type Message

type Message struct {
	Subject     string
	FromAddr    string
	FromName    string
	To          []string
	CC          []string
	Bcc         []string
	Text        string
	HTML        string
	Attachments []*Attachment
}

Message 邮件消息体

func NewMessage

func NewMessage() *Message

================= message api =================

func (*Message) AddAttachment

func (m *Message) AddAttachment(attachment *Attachment)

func (*Message) AddBCC

func (m *Message) AddBCC(c string)

func (*Message) AddCC

func (m *Message) AddCC(c string)

func (*Message) AddTo

func (m *Message) AddTo(tos ...string)

func (*Message) AttachFile

func (m *Message) AttachFile(fileName string) error

func (*Message) Reset

func (m *Message) Reset()

func (*Message) SetFrom

func (m *Message) SetFrom(name, from string)

func (*Message) SetHTML

func (m *Message) SetHTML(html string)

func (*Message) SetSubject

func (m *Message) SetSubject(subject string)

func (*Message) SetText

func (m *Message) SetText(text string)

type XMailer

type XMailer struct {
	Addr string
	Host string
	// contains filtered or unexported fields
}

XMailer 邮件客户端

func NewXMailer

func NewXMailer(addr, username, passwd string) (*XMailer, error)

func NewXMailerWithStartTLS

func NewXMailerWithStartTLS(addr, username, passwd string, tlsConfig *tls.Config) (*XMailer, error)

func (*XMailer) Auth

func (x *XMailer) Auth() error

func (*XMailer) Dial

func (x *XMailer) Dial() error

func (*XMailer) DialWithStartTLS

func (x *XMailer) DialWithStartTLS(t *tls.Config) error

func (*XMailer) DialWithTLS

func (x *XMailer) DialWithTLS(t *tls.Config) error

func (*XMailer) Quit

func (x *XMailer) Quit()

func (*XMailer) Send

func (x *XMailer) Send(m *Message) error

Jump to

Keyboard shortcuts

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