Mercurial > gemma
annotate pkg/misc/mail.go @ 578:61af85a432bf
Fix extraction of object reference code
Use something more distinguishing in test to make it more likely
to catch similar errors.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 06 Sep 2018 13:19:51 +0200 |
parents | c1047fd04a3a |
children | a244b18cb916 |
rev | line source |
---|---|
339
33b59c848771
Factored out some miscellaneous code into own package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
1 package misc |
33b59c848771
Factored out some miscellaneous code into own package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
2 |
33b59c848771
Factored out some miscellaneous code into own package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
3 import ( |
33b59c848771
Factored out some miscellaneous code into own package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
4 gomail "gopkg.in/gomail.v2" |
33b59c848771
Factored out some miscellaneous code into own package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
5 |
414
c1047fd04a3a
Moved project specific Go packages to new pkg folder.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
339
diff
changeset
|
6 "gemma.intevation.de/gemma/pkg/config" |
339
33b59c848771
Factored out some miscellaneous code into own package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
7 ) |
33b59c848771
Factored out some miscellaneous code into own package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
8 |
33b59c848771
Factored out some miscellaneous code into own package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
9 func SendMail(email, subject, body string) error { |
33b59c848771
Factored out some miscellaneous code into own package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
10 m := gomail.NewMessage() |
33b59c848771
Factored out some miscellaneous code into own package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
11 m.SetHeader("From", config.MailFrom()) |
33b59c848771
Factored out some miscellaneous code into own package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
12 m.SetHeader("To", email) |
33b59c848771
Factored out some miscellaneous code into own package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
13 m.SetHeader("Subject", subject) |
33b59c848771
Factored out some miscellaneous code into own package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
14 m.SetBody("text/plain", body) |
33b59c848771
Factored out some miscellaneous code into own package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
15 |
33b59c848771
Factored out some miscellaneous code into own package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
16 d := gomail.Dialer{ |
33b59c848771
Factored out some miscellaneous code into own package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
17 Host: config.MailHost(), |
33b59c848771
Factored out some miscellaneous code into own package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
18 Port: int(config.MailPort()), |
33b59c848771
Factored out some miscellaneous code into own package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
19 Username: config.MailUser(), |
33b59c848771
Factored out some miscellaneous code into own package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
20 Password: config.MailPassword(), |
33b59c848771
Factored out some miscellaneous code into own package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
21 LocalName: config.MailHelo(), |
33b59c848771
Factored out some miscellaneous code into own package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
22 SSL: config.MailPort() == 465, |
33b59c848771
Factored out some miscellaneous code into own package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
23 } |
33b59c848771
Factored out some miscellaneous code into own package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
24 |
33b59c848771
Factored out some miscellaneous code into own package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
25 return d.DialAndSend(m) |
33b59c848771
Factored out some miscellaneous code into own package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
26 } |