service

package module
v0.0.0-...-3e52450 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2013 License: MIT Imports: 9 Imported by: 0

README

用途

邮件发送服务

安装

go get github.com/miraclesu/service

使用

c := service.SmtpConf{
    "Host":     "smtp.gmail.com",
    "Port":     25,
    "Username": "sample@gmail.com",
    "Password": "password",
    "AuthType": "plain",
}
serv := service.New(l)
s := service.NewSmtpServer(&c)
if err := serv.AddServer(s); err != nil {
    //handler err
}
serv.Work()

msg := service.Message{
    "SenderName" => "xx",
    "From" => "sample@gmail.com",
    "To" => map[string]string{"to_name":"name@xx.com"},
    "Subject" => "邮件标题——PHP测试",
    "Body" => "我是邮件xx, golang出品!",
    "Tag" => "smtp",
}
serv.Send(&msg)

配置文件参数说明

config.json配置参数说明:

Config为一个数组,每个元素为一台邮件服务器,服务器的配置说明:

  • Host: 邮件服务器的smtp
  • Port: smtp的端口
  • Username: 邮件服务器的发送帐户
  • Password: 发送帐户的密码
  • AuthType: smtp的验证方式
  • TimeOut: smtp协议中client连接的保持时间,单位s
  • SickLimit: smtp服务器的超时时间,单位s
  • SickStep: 检测smtp服务器有问题时给smtp加上的超时时间,单位s

Authors

miraclesu

Open Source - MIT Software License

Documentation

Index

Constants

View Source
const (
	ErrTimes  = 3
	TickStep  = 20 * time.Second
	Unlimited = 0
)
View Source
const (
	//authTypes
	Plain       = "plain"
	MD5         = "cram-md5"
	Unencrypted = "unencrypted"

	//tags
	SMTP = "smtp"

	//conf
	Limit = 60 * 60
	Step  = 21 * 60
)

Variables

View Source
var (
	ErrNoActiveServer = errors.New("No active server.")
	ErrServiceWarning = errors.New("The Service does not running.")
)

Functions

func Errorf

func Errorf(format string, msg ...interface{}) error

Types

type ErrorHandler

type ErrorHandler func(e error)

type Message

type Message struct {
	Id         bson.ObjectId
	SenderName string
	From       string
	To         map[string]string
	Subject    string
	Body       string
	Tag        string
	Mass       bool
	Times      int
}

type MessageHandler

type MessageHandler func(e error)

type Server

type Server interface {
	Init(conf ...interface{}) error
	Send(m *Message) error
	Close() error
	Rate() time.Time
	Tag() string
	Running() bool
	Timeout() bool
	Sick() bool
}

func NewSmtpServer

func NewSmtpServer(conf *SmtpConf) (server Server)

type ServerList

type ServerList map[string][]Server

type Service

type Service struct {
	ErrHandler ErrorHandler
	MsgHandler MessageHandler
	// contains filtered or unexported fields
}

func New

func New(l int) (s *Service)

func (*Service) AddServer

func (s *Service) AddServer(server Server, conf ...interface{}) (err error)

func (*Service) Close

func (s *Service) Close()

func (*Service) RemoveServer

func (s *Service) RemoveServer(server Server)

func (*Service) Send

func (s *Service) Send(m *Message) error

func (*Service) Work

func (s *Service) Work()

type SmtpConf

type SmtpConf struct {
	Host     string
	Port     int
	Username string
	Password string
	AuthType string
	//options
	TimeOut   uint32
	SickLimit uint32
	SickStep  uint32
}

type SmtpServer

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

func (*SmtpServer) Close

func (s *SmtpServer) Close() (err error)

func (*SmtpServer) Init

func (s *SmtpServer) Init(conf ...interface{}) (err error)

func (*SmtpServer) Rate

func (s *SmtpServer) Rate() time.Time

func (*SmtpServer) Running

func (s *SmtpServer) Running() bool

func (*SmtpServer) Send

func (s *SmtpServer) Send(m *Message) error

func (*SmtpServer) Sick

func (s *SmtpServer) Sick() bool

func (*SmtpServer) Tag

func (s *SmtpServer) Tag() string

func (*SmtpServer) Timeout

func (s *SmtpServer) Timeout() bool

Jump to

Keyboard shortcuts

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