Example #1
0
func Send(sender string, subject string, message string, recipient string) error {
	m := mailgun.NewMessage(sender, subject, message, recipient)
	m.SetHtml(message)
	_, _, err := gun.Send(m)
	Log.Debug("%+v", err)

	return err
}
Example #2
0
func TestSendLegacyPlain(t *testing.T) {
	toUser := reqEnv(t, "MG_EMAIL_TO")
	domain := reqEnv(t, "MG_DOMAIN")
	apiKey := reqEnv(t, "MG_API_KEY")
	publicApiKey := reqEnv(t, "MG_PUBLIC_API_KEY")
	mg := mailgun.NewMailgun(domain, apiKey, publicApiKey)
	m := mailgun.NewMessage(fromUser, exampleSubject, exampleText, toUser)
	msg, id, err := mg.Send(m)
	if err != nil {
		t.Fatal(err)
	}
	fmt.Println("TestSendPlain:MSG(" + msg + "),ID(" + id + ")")
}
Example #3
0
// sendWithMailgun handles the main send and logging logic for any single email deploy
func (c *Client) sendWithMailgun() (string, error) {
	var err error

	c.Body, err = c.prepareTmpl()
	if err != nil {
		return "", err
	}

	gun := mg.NewMailgun(Conf["mailgun"]["domain"], Conf["mailgun"]["secret"], Conf["mailgun"]["public"])

	// override the http client
	client := urlfetch.Client(c.context)
	gun.SetClient(client)

	// generate mailgun message
	message := mg.NewMessage(fmt.Sprintf("%s <%s>", Conf["default"]["fromname"], Conf["default"]["fromemail"]), c.Subject, c.Body, c.Recipient[0].Render)
	message.SetHtml(strings.Replace(c.Body, "\\", "", -1))

	// add additional recipients
	for k, v := range c.Recipient {
		if k > 0 {
			err := message.AddRecipient(v.Render)
			if err != nil {
				c.context.Errorf("Could not append [%s] as Mailgun recipient: %v", v.Render, err)
				return "", err
			}
		}
	}

	// send the email
	_, id, err := gun.Send(message)
	if err != nil {
		c.context.Errorf("Error: %v", err)
		return "", err
	}

	if Conf["default"]["logmessages"] == "true" {
		// if the id is not empty then add to the message log
		if id != "" {
			_, logErr := c.addMessageLog()
			if logErr != nil {
				c.context.Errorf("Failed to add message to log: %v", logErr)
			}
		}
	}

	return id, err
}
Example #4
0
func NotifyUser(name, email, subject, message string) {
	fmt.Printf("Notifying %s with subject:\n", email)
	fmt.Printf("%s\n", subject)

	mailto := fmt.Sprintf("%s <%s>", name, email)
	gun := mailgun.NewMailgun("mail.ckpt.no", os.Getenv("CKPT_MAILGUN_KEY"), "pubkey-b3e133632123a0da24d1e2c5842039b6")
	m := mailgun.NewMessage("CKPT <*****@*****.**>", subject, message, mailto)
	m.AddHeader("Content-Type", "text/plain; charset=\"utf-8\"")
	response, id, err := gun.Send(m)

	if err != nil {
		fmt.Printf("Error:\n%+v\n", err.Error())
	}
	fmt.Printf("Response ID: %s\n", id)
	fmt.Printf("Message from server: %s\n", response)
}
Example #5
0
func (m *mailgunner) Send(msg string, sender string, subject string, to string) error {
	if len(strings.TrimSpace(sender)) <= 0 {
		sender = "Kishore CEO <*****@*****.**>"
	}
	mg := mailgun.NewMailgun(m.domain, m.api_key, "")
	g := mailgun.NewMessage(
		sender,
		subject,
		"You are in !",
		to,
	)
	g.SetHtml(msg)
	g.SetTracking(true)
	_, id, err := mg.Send(g)
	if err != nil {
		return err
	}
	log.Infof("Mailgun sent %s", id)
	return nil
}
Example #6
0
func (m *mailgunner) Send(msg string, sender string, subject string, to string) error {
	if len(strings.TrimSpace(sender)) <= 0 {
		sender = m.sender
	}
	mg := mailgun.NewMailgun(m.domain, m.api_key, "")
	g := mailgun.NewMessage(
		sender,
		subject,
		"You are in !",
		to,
	)
	g.SetHtml(msg)
	g.SetTracking(false)
	//g.SetTrackingClicks(false)
	//g.SetTrackingOpens(false)
	_, id, err := mg.Send(g)
	if err != nil {
		return err
	}
	log.Infof("Mailgun sent %s", id)
	return nil
}