Esempio n. 1
0
func NewEmailServer() *EmailServer {

	es := EmailServer{
		dbo: orm.ReadConfig("email.server.database"),
		auth: smtp.PlainAuth(
			conf.String("", "email.server.smtp.auth", "identity"),
			conf.String("", "email.server.smtp.auth", "username"),
			conf.String("", "email.server.smtp.auth", "password"),
			conf.String("", "email.server.smtp.auth", "host"),
		),
	}

	// testing
	es.dbo.LogMode(true)

	es.address = conf.String("", "email.server.smtp", "host")
	if conf.Exists("email.server.smtp", "port") {
		es.address = fmt.Sprintf("%s:%d", es.address, conf.Int(0, "email.server.smtp", "port"))
	}

	if conf.Exists("email.queue.default") {
		es.queue = que.NewQueue("email.queue.default")
	}

	// create relational tables if missing
	if !es.dbo.HasTable(Message{}) {
		panik.On(es.dbo.AutoMigrate(&Message{}).Error)
		fmt.Println("[message] table created.")
	}

	return &es
}
Esempio n. 2
0
func init() {
	if conf.Exists("email.queue.default") {
		Queue = que.NewQueue("email.queue.default")
	}
}