diff options
author | zeripath <art27@cantab.net> | 2019-02-03 02:06:52 +0000 |
---|---|---|
committer | techknowlogick <matti@mdranta.net> | 2019-02-02 21:06:52 -0500 |
commit | 3d91bb2f2dc8584b76a49a1a40c3f688c21380f5 (patch) | |
tree | 5f5641012972139a1fb179a5415cab38c222a68a /modules | |
parent | 67567eff0e5614553cbd396ae7e1adfde6fa33c0 (diff) | |
download | gitea-3d91bb2f2dc8584b76a49a1a40c3f688c21380f5.tar.gz gitea-3d91bb2f2dc8584b76a49a1a40c3f688c21380f5.zip |
Make log mailer for testing (#5893)
* Create log mailer for testing email settings
Signed-off-by: Andrew Thornton <art27@cantab.net>
* Switch on the log mailer for the integration tests
This ensures that the sending mail process works
Signed-off-by: Andrew Thornton <art27@cantab.net>
* rename the from user for mysql/mssql
* rename log sender to dummy sender
* update the integration tests
Diffstat (limited to 'modules')
-rw-r--r-- | modules/mailer/mailer.go | 24 | ||||
-rw-r--r-- | modules/setting/setting.go | 17 |
2 files changed, 35 insertions, 6 deletions
diff --git a/modules/mailer/mailer.go b/modules/mailer/mailer.go index e9b752e14d..6f4c9488d5 100644 --- a/modules/mailer/mailer.go +++ b/modules/mailer/mailer.go @@ -6,6 +6,7 @@ package mailer import ( + "bytes" "crypto/tls" "fmt" "io" @@ -237,6 +238,20 @@ func (s *sendmailSender) Send(from string, to []string, msg io.WriterTo) error { } } +// Sender sendmail mail sender +type dummySender struct { +} + +// Send send email +func (s *dummySender) Send(from string, to []string, msg io.WriterTo) error { + buf := bytes.Buffer{} + if _, err := msg.WriteTo(&buf); err != nil { + return err + } + log.Info("Mail From: %s To: %v Body: %s", from, to, buf.String()) + return nil +} + func processMailQueue() { for { select { @@ -265,10 +280,13 @@ func NewContext() { return } - if setting.MailService.UseSendmail { - Sender = &sendmailSender{} - } else { + switch setting.MailService.MailerType { + case "smtp": Sender = &smtpSender{} + case "sendmail": + Sender = &sendmailSender{} + case "dummy": + Sender = &dummySender{} } mailQueue = make(chan *Message, setting.MailService.QueueLength) diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 4aca579617..a2fdbf5192 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -1529,6 +1529,7 @@ type Mailer struct { FromName string FromEmail string SendAsPlainText bool + MailerType string // SMTP sender Host string @@ -1541,7 +1542,6 @@ type Mailer struct { IsTLSEnabled bool // Sendmail sender - UseSendmail bool SendmailPath string SendmailArgs []string } @@ -1562,6 +1562,7 @@ func newMailService() { QueueLength: sec.Key("SEND_BUFFER_LEN").MustInt(100), Name: sec.Key("NAME").MustString(AppName), SendAsPlainText: sec.Key("SEND_AS_PLAIN_TEXT").MustBool(false), + MailerType: sec.Key("MAILER_TYPE").In("", []string{"smtp", "sendmail", "dummy"}), Host: sec.Key("HOST").String(), User: sec.Key("USER").String(), @@ -1574,7 +1575,6 @@ func newMailService() { KeyFile: sec.Key("KEY_FILE").String(), IsTLSEnabled: sec.Key("IS_TLS_ENABLED").MustBool(), - UseSendmail: sec.Key("USE_SENDMAIL").MustBool(), SendmailPath: sec.Key("SENDMAIL_PATH").MustString("sendmail"), } MailService.From = sec.Key("FROM").MustString(MailService.User) @@ -1584,6 +1584,13 @@ func newMailService() { MailService.SendAsPlainText = !sec.Key("ENABLE_HTML_ALTERNATIVE").MustBool(false) } + if sec.HasKey("USE_SENDMAIL") { + log.Warn("USE_SENDMAIL is deprecated, use MAILER_TYPE=sendmail") + if MailService.MailerType == "" && sec.Key("USE_SENDMAIL").MustBool(false) { + MailService.MailerType = "sendmail" + } + } + parsed, err := mail.ParseAddress(MailService.From) if err != nil { log.Fatal(4, "Invalid mailer.FROM (%s): %v", MailService.From, err) @@ -1591,7 +1598,11 @@ func newMailService() { MailService.FromName = parsed.Name MailService.FromEmail = parsed.Address - if MailService.UseSendmail { + if MailService.MailerType == "" { + MailService.MailerType = "smtp" + } + + if MailService.MailerType == "sendmail" { MailService.SendmailArgs, err = shellquote.Split(sec.Key("SENDMAIL_ARGS").String()) if err != nil { log.Error(4, "Failed to parse Sendmail args: %v", CustomConf, err) |