Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions custom/conf/app.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,8 @@ USER =
PASSWD =
; Send mails as plain text
SEND_AS_PLAIN_TEXT = false
; Enable sendmail (override SMTP)
USE_SENDMAIL = false
; Set Mailer Type (either SMTP, sendmail or just send to log)
MAILER_TYPE = smtp
; Specify an alternative sendmail binary
SENDMAIL_PATH = sendmail
; Specify any extra sendmail arguments
Expand Down
6 changes: 5 additions & 1 deletion docs/content/doc/advanced/config-cheat-sheet.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,14 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
- `PASSWD`: **\<empty\>**: Password of mailing user. Use \`your password\` for quoting if you use special characters in the password.
- `SKIP_VERIFY`: **\<empty\>**: Do not verify the self-signed certificates.
- **Note:** Gitea only supports SMTP with STARTTLS.
- `USE_SENDMAIL`: **false** Use the operating system's `sendmail` command instead of SMTP.
- `MAILER_TYPE`: **smtp**: \[smtp, sendmail, log\]
- **smtp** Use SMTP to send mail
- **sendmail** Use the operating system's `sendmail` command instead of SMTP.
This is common on linux systems.
- **log** Send email messages to the log as a testing phase.
- Note that enabling sendmail will ignore all other `mailer` settings except `ENABLED`,
`FROM` and `SENDMAIL_PATH`.
- Enabling log will ignore all settings except `ENABLED` and `FROM`.
- `SENDMAIL_PATH`: **sendmail**: The location of sendmail on the operating system (can be
command or full path).
- ``IS_TLS_ENABLED`` : **false** : Decide if SMTP connections should use TLS.
Expand Down
5 changes: 4 additions & 1 deletion integrations/mssql.ini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ LFS_JWT_SECRET = Tv_MjmZuHqpIY6GFl12ebgkRAMt4RlWt0v4EHKSXO0w
APP_DATA_PATH = integrations/gitea-integration-mssql/data

[mailer]
ENABLED = false
ENABLED = true
MAILER_TYPE = log
FROM = mssql-integration-test@gitea.io

[service]
REGISTER_EMAIL_CONFIRM = false
Expand All @@ -47,6 +49,7 @@ REQUIRE_SIGNIN_VIEW = false
DEFAULT_KEEP_EMAIL_PRIVATE = false
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
NO_REPLY_ADDRESS = noreply.example.org
ENABLE_NOTIFY_MAIL = true

[picture]
DISABLE_GRAVATAR = false
Expand Down
5 changes: 4 additions & 1 deletion integrations/mysql.ini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ LFS_JWT_SECRET = Tv_MjmZuHqpIY6GFl12ebgkRAMt4RlWt0v4EHKSXO0w
APP_DATA_PATH = integrations/gitea-integration-mysql/data

[mailer]
ENABLED = false
ENABLED = true
MAILER_TYPE = log
FROM = mysql-integration-test@gitea.io

[service]
REGISTER_EMAIL_CONFIRM = false
Expand All @@ -47,6 +49,7 @@ REQUIRE_SIGNIN_VIEW = false
DEFAULT_KEEP_EMAIL_PRIVATE = false
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
NO_REPLY_ADDRESS = noreply.example.org
ENABLE_NOTIFY_MAIL = true

[picture]
DISABLE_GRAVATAR = false
Expand Down
5 changes: 4 additions & 1 deletion integrations/pgsql.ini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ LFS_JWT_SECRET = Tv_MjmZuHqpIY6GFl12ebgkRAMt4RlWt0v4EHKSXO0w
APP_DATA_PATH = integrations/gitea-integration-pgsql/data

[mailer]
ENABLED = false
ENABLED = true
MAILER_TYPE = log
FROM = pgsql-integration-test@gitea.io

[service]
REGISTER_EMAIL_CONFIRM = false
Expand All @@ -47,6 +49,7 @@ REQUIRE_SIGNIN_VIEW = false
DEFAULT_KEEP_EMAIL_PRIVATE = false
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
NO_REPLY_ADDRESS = noreply.example.org
ENABLE_NOTIFY_MAIL = true

[picture]
DISABLE_GRAVATAR = false
Expand Down
6 changes: 6 additions & 0 deletions integrations/sqlite.ini
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ REQUIRE_SIGNIN_VIEW = false
DEFAULT_KEEP_EMAIL_PRIVATE = false
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
NO_REPLY_ADDRESS = noreply.example.org
ENABLE_NOTIFY_MAIL = true

[picture]
DISABLE_GRAVATAR = false
Expand All @@ -66,3 +67,8 @@ LEVEL = Debug
INSTALL_LOCK = true
SECRET_KEY = 9pCviYTWSb
INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0OTI3OTU5ODN9.OQkH5UmzID2XBdwQ9TAI6Jj2t1X-wElVTjbE7aoN4I8

[mailer]
ENABLED = true
MAILER_TYPE = log
FROM = sqlite-integration-test@gitea.io
24 changes: 21 additions & 3 deletions modules/mailer/mailer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package mailer

import (
"bytes"
"crypto/tls"
"fmt"
"io"
Expand Down Expand Up @@ -237,6 +238,20 @@ func (s *sendmailSender) Send(from string, to []string, msg io.WriterTo) error {
}
}

// Sender sendmail mail sender
type logSender struct {
}

// Send send email
func (s *logSender) 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 {
Expand Down Expand Up @@ -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 "log":
Sender = &logSender{}
}

mailQueue = make(chan *Message, setting.MailService.QueueLength)
Expand Down
17 changes: 14 additions & 3 deletions modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -1529,6 +1529,7 @@ type Mailer struct {
FromName string
FromEmail string
SendAsPlainText bool
MailerType string

// SMTP sender
Host string
Expand All @@ -1541,7 +1542,6 @@ type Mailer struct {
IsTLSEnabled bool

// Sendmail sender
UseSendmail bool
SendmailPath string
SendmailArgs []string
}
Expand All @@ -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", "log"}),

Host: sec.Key("HOST").String(),
User: sec.Key("USER").String(),
Expand All @@ -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)
Expand All @@ -1584,14 +1584,25 @@ 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)
}
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)
Expand Down