예제 #1
0
파일: mailnotify.go 프로젝트: grr89/hrkb
//Recieves Mail Service config
//And initializes ne NotifyMail obj and returns it
func NewNotifyMail(conf NotifyMailConfig, nChan NotificationChannel, eChan ErrorChannel) *NotifyMail {
	c := mandrill.ClientWithKey(conf.Apikey)

	c.HTTPClient.Timeout = time.Duration(conf.Timeout) * time.Second

	rps := 1

	//Computing rate Per Millisecond
	if conf.RatePerH > 3600000 {
		rps = 36000000 / conf.RatePerH
	}

	mail := NotifyMail{
		client:    c,
		store:     MailStore{conf.DB, conf.Retry},
		notifChan: nChan,
		sendChan:  make(chan M.Mail, conf.BuffLimit),
		waitTime:  conf.WaitTime,
		retry:     conf.Retry,
		closeChan: make(chan bool),
		errChan:   eChan,
		rpms:      rps,
		frpm:      conf.RetryFailedPerMin,
	}

	return &mail
}
예제 #2
0
// NotifyEMail utilizes the Mandrill API to send a predefined template for the
// current build
func (n *NotifyEntry) NotifyEMail(metadata NotifyMetaData, cfg *config.Config) error {
	verb := "successful"
	if metadata.EventType == "error" {
		verb = "failed"
	}

	c := mandrill.ClientWithKey(cfg.Mandrill.MandrillAPIKey)
	message := &mandrill.Message{}
	message.AddRecipient(n.Target, "Gopher", "to")
	message.GlobalMergeVars = mandrill.MapToVars(map[string]interface{}{
		"REPO":      metadata.Repository,
		"STATE":     verb,
		"REPO_LINK": fmt.Sprintf("https://gobuilder.me/%s", metadata.Repository),
		"EMAIL":     n.Target,
	})
	message.AutoText = true
	message.TrackOpens = true
	message.TrackClicks = true
	message.InlineCSS = true

	templateContent := map[string]string{}
	_, err := c.MessagesSendTemplate(message, "gobuilder-status-mail", templateContent)

	return err
}
예제 #3
0
func main() {
	client := m.ClientWithKey(os.Getenv("MANDRILL_KEY"))
	subject := os.Getenv("SUBJECT")
	to := os.Getenv("TO")

	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		raw_message := r.PostFormValue("message")
		from := r.PostFormValue("from")
		log.Println("sending message")
		message := &m.Message{}
		message.AddRecipient(to, "", "to")
		message.FromEmail = from
		message.Subject = subject
		message.Text = raw_message

		if _, err := client.MessagesSend(message); err != nil {
			log.Println(err)
			w.WriteHeader(500)
			w.Write([]byte("Message send failed"))
		} else {
			w.WriteHeader(200)
			w.Write([]byte("Message sent."))
		}
	})
	log.Fatal(http.ListenAndServe(":8888", nil))
}
예제 #4
0
// New returns a Mailer with mandrill client
func New(key, fromEmail, fromName string) Mailer {
	return Mailer{
		fromEmail: fromEmail,
		fromName:  fromName,
		client:    mandrill.ClientWithKey(key),
	}
}
예제 #5
0
func main() {
	conn, err := amqp.Dial(cfg.Amqp.Hostname)
	fatalOnError(err, "Failed to connect to RabbitMQ")
	defer conn.Close()

	ch, err := conn.Channel()
	fatalOnError(err, "Failed to open a channel")
	defer ch.Close()

	fmt.Println("Queue Name:", cfg.Amqp.MessageQueue)
	q, err := ch.QueueDeclare(
		cfg.Amqp.MessageQueue, // name
		true,  // durable
		false, // delete when unused
		false, // exclusive
		false, // no-wait
		nil,   // arguments
	)
	fatalOnError(err, "Failed to declare a queue")

	err = ch.Qos(
		1,     // prefetch count
		0,     // prefetch size
		false, // global
	)
	fatalOnError(err, "Failed to set QoS")

	msgs, err := ch.Consume(
		q.Name, // queue
		"",     // consumer
		false,  // auto-ack
		false,  // exclusive
		false,  // no-local
		false,  // no-wait
		nil,    // args
	)
	fatalOnError(err, "Failed to register a consumer")

	forever := make(chan bool)

	go func() {
		mclient := mandrill.ClientWithKey(cfg.Mandrill.ClientKey)

		fmt.Println("Waiting for new incoming messages to consume...")
		for rawMsg := range msgs {
			fmt.Println("Consuming incoming message...")
			decodedMsg := imapClient.NewMessageFromBytes(rawMsg.Body)
			forwardMessage(mclient, decodedMsg)
			rawMsg.Ack(false)
			fmt.Println("Waiting for new incoming messages to consume...")
		}
	}()
	<-forever
}
예제 #6
0
func sendViaMandrill(subject string, body string) {
	client := mandrill.ClientWithKey(os.Getenv("MANDRILL_API_KEY"))
	message := &mandrill.Message{}
	message.AddRecipient(os.Getenv("TO_EMAIL"), os.Getenv("TO_NAME"), "to")
	message.FromEmail = os.Getenv("FROM_EMAIL")
	message.FromName = os.Getenv("FROM_NAME")
	message.Subject = subject
	message.HTML = body

	_, err := client.MessagesSend(message)
	if err != nil {
		log.Print(err)
	}
}
예제 #7
0
func emailResults(s string) {
	log.Print(s)

	client := m.ClientWithKey(os.Getenv("MANDRILL"))

	message := &m.Message{}
	message.AddRecipient(os.Getenv("EMAIL"), "", "to")
	message.FromEmail = os.Getenv("EMAIL")
	message.FromName = "Go Get IP"
	message.Subject = "IP address"
	message.Text = s

	client.MessagesSend(message)
}
예제 #8
0
파일: main.go 프로젝트: extranjero/codes
func main() {
	client := m.ClientWithKey("TOKEN")

	message := &m.Message{}
	message.AddRecipient("*****@*****.**", "Abdullo Xidoyatov", "to")
	message.FromEmail = "*****@*****.**"
	message.FromName = "Shoptolidan"
	message.Subject = "Test"
	message.HTML = "<h1>You won!!</h1>"

	responses, err := client.MessagesSend(message)

	if err != nil {
		log.Fatal("Message send error: ", err)
	}

	fmt.Println("Responces ", responses)
}
예제 #9
0
// send mail notification to admin(s)
func sendMail(mail_details *emailDetails) {
	os_env_vars := getOSEnv()

	//validate os env vars. fail otherwise!
	if os_env_vars.api_key == "" {
		log.Println("OS env variable 'MANDRILL_KEY' is not defined!")
		os.Exit(2)
	} else if len(os_env_vars.email_dest_addr) <= 0 {
		log.Println("OS env variable 'EMAIL_DEST_ADDR' is not defined!")
		os.Exit(2)
	} else if os_env_vars.email_src_addr == "" {
		log.Println("OS env variable 'EMAIL_SRC_ADDR' is not defined!")
		os.Exit(2)
	}

	client := mandrill.ClientWithKey(os_env_vars.api_key)

	message := &mandrill.Message{}
	message.FromEmail = os_env_vars.email_src_addr
	message.FromName = os_env_vars.email_src_name
	for _, recipient := range os_env_vars.email_dest_addr {
		message.AddRecipient(recipient, "", "to")
	}
	message.Subject = mail_details.subject
	message.Text = mail_details.mail_text
	if mail_details.mail_html != "" {
		message.HTML = mail_details.mail_html
	}

	//send the mail(s)
	responses, err := client.MessagesSend(message)

	//show error details if mail(s) not sent
	if err != nil {
		fmt.Println("Unable to send mail(s)" + err.Error())
		for _, response := range responses {
			log.Printf("Unable to send mail to %s. Reason: %s", response.Email, response.RejectionReason)
		}
	} else {
		log.Println("Mail(s) sent!")
	}
}
예제 #10
0
func (p *program) init() {
	ROOT_DIR, _ = osext.ExecutableFolder()

	config.LoadConfig(ROOT_DIR + "/config.json")

	// Start with external services
	p.mailer = mandrill.ClientWithKey(config.Config.Services.Mandrill.Key)
	rollbar.Environment = config.Config.Services.Rollbar.Environment
	rollbar.Token = config.Config.Services.Rollbar.Token

	// Now the games
	p.daily = &fpl.Daily{}
	p.stockpot = &fpl.Stockpot{}
	p.survey = &fpl.Survey{}

	// And finally the main worker
	p.client = fpl.NewClient(p.daily, p.stockpot, p.survey)
	if err := p.client.Login(); err != nil {
		logger.Error(err)
	}

}