Ejemplo n.º 1
0
// ---------------------------------------------------------------
//
// Implementation
//
// ---------------------------------------------------------------
func New(log *log.Logger, config map[string]string, fs mtacontainer.FailureStrategy) mtacontainer.MTAProvider {
	var result *MailGunProvider = new(MailGunProvider)

	result.failureStrategy = fs

	// -- initialize the result --
	result.config = config
	var apiKey = utilities.DecryptApiKey(config[MG_CNF_PASSPHRASE], config[MG_CNF_ENCRYPTED_APIKEY],
		goh.StrToInt(config[MG_CNF_ENCRYPTED_APIKEY_LEN]))

	result.mg = mailgun.NewMailgun(config[MG_CNF_DOMAIN_TO_SERVE], apiKey, "")
	result.log = log

	// setup channels
	result.out = make(chan model.Email)
	result.inc = make(chan model.Email)
	result.cmd = make(chan Cmd)
	result.events = make(chan mtacontainer.Event)

	// for routines to serve
	go result.sendingRoutine()
	//go result.receivingRoutine();

	log.Println(result.GetName() + " MTA Going up")

	// send initial "MG is in the Air"-message to Admin
	//result.sendMaintanenceMessage("Admin,\nPlease find the MailGun MTA provider is up.");

	return result
}
Ejemplo n.º 2
0
func New(log *log.Logger, config map[string]string, fs mtacontainer.FailureStrategy) mtacontainer.MTAProvider {
	var result = new(SendGridProvider)
	result.incoming = make(chan model.Email)
	result.outgoing = make(chan model.Email)
	result.events = make(chan mtacontainer.Event)
	result.cmd = make(chan commandprotocol.Command)
	result.log = log
	result.log.Println(result.GetName() + " MTA Going up")

	var apiKey = utilities.DecryptApiKey(config[SG_CNF_PASSPHRASE], config[SG_CNF_ENC_API_KEY],
		goh.StrToInt(config[SG_CNF_API_KEY_LEN]))
	result.sg = sendgrid.NewSendGridClientWithApiKey(apiKey)

	result.failureStrategy = fs

	go result.sendingRoutine()
	return result
}