Skip to content

Commit f7eca50

Browse files
clarfontheywxiaoguanglunny
authored and
Sysoev, Vladimir
committed
Rework mailer settings (go-gitea#18982)
* `PROTOCOL`: can be smtp, smtps, smtp+startls, smtp+unix, sendmail, dummy * `SMTP_ADDR`: domain for SMTP, or path to unix socket * `SMTP_PORT`: port for SMTP; defaults to 25 for `smtp`, 465 for `smtps`, and 587 for `smtp+startls` * `ENABLE_HELO`, `HELO_HOSTNAME`: reverse `DISABLE_HELO` to `ENABLE_HELO`; default to false + system hostname * `FORCE_TRUST_SERVER_CERT`: replace the unclear `SKIP_VERIFY` * `CLIENT_CERT_FILE`, `CLIENT_KEY_FILE`, `USE_CLIENT_CERT`: clarify client certificates here Co-authored-by: wxiaoguang <[email protected]> Co-authored-by: Lunny Xiao <[email protected]>
1 parent cd07f17 commit f7eca50

File tree

14 files changed

+297
-155
lines changed

14 files changed

+297
-155
lines changed

cmd/admin.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,9 @@ var (
414414
Usage: "SMTP Authentication Type (PLAIN/LOGIN/CRAM-MD5) default PLAIN",
415415
},
416416
cli.StringFlag{
417-
Name: "host",
417+
Name: "addr",
418418
Value: "",
419-
Usage: "SMTP Host",
419+
Usage: "SMTP Addr",
420420
},
421421
cli.IntFlag{
422422
Name: "port",
@@ -956,8 +956,8 @@ func parseSMTPConfig(c *cli.Context, conf *smtp.Source) error {
956956
}
957957
conf.Auth = c.String("auth-type")
958958
}
959-
if c.IsSet("host") {
960-
conf.Host = c.String("host")
959+
if c.IsSet("addr") {
960+
conf.Addr = c.String("addr")
961961
}
962962
if c.IsSet("port") {
963963
conf.Port = c.Int("port")

custom/conf/app.example.ini

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,50 +1503,58 @@ ROUTER = console
15031503
;; Prefix displayed before subject in mail
15041504
;SUBJECT_PREFIX =
15051505
;;
1506-
;; Mail server
1507-
;; Gmail: smtp.gmail.com:587
1508-
;; QQ: smtp.qq.com:465
1509-
;; As per RFC 8314 using Implicit TLS/SMTPS on port 465 (if supported) is recommended,
1510-
;; otherwise STARTTLS on port 587 should be used.
1511-
;HOST =
1512-
;;
1513-
;; Disable HELO operation when hostnames are different.
1514-
;DISABLE_HELO =
1515-
;;
1516-
;; Custom hostname for HELO operation, if no value is provided, one is retrieved from system.
1506+
;; Mail server protocol. One of "smtp", "smtps", "smtp+startls", "smtp+unix", "sendmail", "dummy".
1507+
;; - sendmail: use the operating system's `sendmail` command instead of SMTP. This is common on Linux systems.
1508+
;; - dummy: send email messages to the log as a testing phase.
1509+
;; If your provider does not explicitly say which protocol it uses but does provide a port,
1510+
;; you can set SMTP_PORT instead and this will be inferred.
1511+
;; (Before 1.18, this was controlled via MAILER_TYPE and IS_TLS_ENABLED.)
1512+
;PROTOCOL =
1513+
;;
1514+
;; Mail server address, e.g. smtp.gmail.com.
1515+
;; For smtp+unix, this should be a path to a unix socket instead.
1516+
;; (Before 1.18, this was combined with SMTP_PORT as HOST.)
1517+
;SMTP_ADDR =
1518+
;;
1519+
;; Mail server port. Common ports are:
1520+
;; 25: insecure SMTP
1521+
;; 465: SMTP Secure
1522+
;; 587: StartTLS
1523+
;; If no protocol is specified, it will be inferred by this setting.
1524+
;; (Before 1.18, this was combined with SMTP_ADDR as HOST.)
1525+
;SMTP_PORT =
1526+
;;
1527+
;; Enable HELO operation. Defaults to true.
1528+
;ENABLE_HELO = true
1529+
;;
1530+
;; Custom hostname for HELO operation.
1531+
;; If no value is provided, one is retrieved from system.
15171532
;HELO_HOSTNAME =
15181533
;;
1519-
;; Whether or not to skip verification of certificates; `true` to disable verification. This option is unsafe. Consider adding the certificate to the system trust store instead.
1520-
;SKIP_VERIFY = false
1534+
;; If set to `true`, completely ignores server certificate validation errors.
1535+
;; This option is unsafe. Consider adding the certificate to the system trust store instead.
1536+
;FORCE_TRUST_SERVER_CERT = false
15211537
;;
1522-
;; Use client certificate
1523-
;USE_CERTIFICATE = false
1524-
;CERT_FILE = custom/mailer/cert.pem
1525-
;KEY_FILE = custom/mailer/key.pem
1526-
;;
1527-
;; Should SMTP connect with TLS, (if port ends with 465 TLS will always be used.)
1528-
;; If this is false but STARTTLS is supported the connection will be upgraded to TLS opportunistically.
1529-
;IS_TLS_ENABLED = false
1538+
;; Use client certificate in connection.
1539+
;USE_CLIENT_CERT = false
1540+
;CLIENT_CERT_FILE = custom/mailer/cert.pem
1541+
;CLIENT_KEY_FILE = custom/mailer/key.pem
15301542
;;
15311543
;; Mail from address, RFC 5322. This can be just an email address, or the `"Name" <[email protected]>` format
15321544
;FROM =
15331545
;;
15341546
;; Sometimes it is helpful to use a different address on the envelope. Set this to use ENVELOPE_FROM as the from on the envelope. Set to `<>` to send an empty address.
15351547
;ENVELOPE_FROM =
15361548
;;
1537-
;; Mailer user name and password
1538-
;; Please Note: Authentication is only supported when the SMTP server communication is encrypted with TLS (this can be via STARTTLS) or `HOST=localhost`.
1549+
;; Mailer user name and password, if required by provider.
15391550
;USER =
15401551
;;
15411552
;; Use PASSWD = `your password` for quoting if you use special characters in the password.
15421553
;PASSWD =
15431554
;;
1544-
;; Send mails as plain text
1555+
;; Send mails only in plain text, without HTML alternative
15451556
;SEND_AS_PLAIN_TEXT = false
15461557
;;
1547-
;; Set Mailer Type (either SMTP, sendmail or dummy to just send to the log)
1548-
;MAILER_TYPE = smtp
1549-
;;
15501558
;; Specify an alternative sendmail binary
15511559
;SENDMAIL_PATH = sendmail
15521560
;;

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -647,41 +647,35 @@ Define allowed algorithms and their minimum key length (use -1 to disable a type
647647
## Mailer (`mailer`)
648648

649649
- `ENABLED`: **false**: Enable to use a mail service.
650-
- `DISABLE_HELO`: **\<empty\>**: Disable HELO operation.
651-
- `HELO_HOSTNAME`: **\<empty\>**: Custom hostname for HELO operation.
652-
- `HOST`: **\<empty\>**: SMTP mail host address and port (example: smtp.gitea.io:587).
653-
- As per RFC 8314, if supported, Implicit TLS/SMTPS on port 465 is recommended, otherwise opportunistic TLS via STARTTLS on port 587 should be used.
654-
- `IS_TLS_ENABLED` : **false** : Forcibly use TLS to connect even if not on a default SMTPS port.
655-
- Note, if the port ends with `465` Implicit TLS/SMTPS/SMTP over TLS will be used despite this setting.
656-
- Otherwise if `IS_TLS_ENABLED=false` and the server supports `STARTTLS` this will be used. Thus if `STARTTLS` is preferred you should set `IS_TLS_ENABLED=false`.
657-
- `FROM`: **\<empty\>**: Mail from address, RFC 5322. This can be just an email address, or
658-
the "Name" \<[email protected]\> format.
659-
- `ENVELOPE_FROM`: **\<empty\>**: Address set as the From address on the SMTP mail envelope. Set to `<>` to send an empty address.
650+
- `PROTOCOL`: **\<empty\>**: Mail server protocol. One of "smtp", "smtps", "smtp+startls", "smtp+unix", "sendmail", "dummy". _Before 1.18, this was inferred from a combination of `MAILER_TYPE` and `IS_TLS_ENABLED`._
651+
- SMTP family, if your provider does not explicitly say which protocol it uses but does provide a port, you can set SMTP_PORT instead and this will be inferred.
652+
- **sendmail** Use the operating system's `sendmail` command instead of SMTP. This is common on Linux systems.
653+
- **dummy** Send email messages to the log as a testing phase.
654+
- Note that enabling sendmail will ignore all other `mailer` settings except `ENABLED`, `FROM`, `SUBJECT_PREFIX` and `SENDMAIL_PATH`.
655+
- Enabling dummy will ignore all settings except `ENABLED`, `SUBJECT_PREFIX` and `FROM`.
656+
- `SMTP_ADDR`: **\<empty\>**: Mail server address. e.g. smtp.gmail.com. For smtp+unix, this should be a path to a unix socket instead. _Before 1.18, this was combined with `SMTP_PORT` under the name `HOST`._
657+
- `SMTP_PORT`: **\<empty\>**: Mail server port. If no protocol is specified, it will be inferred by this setting. Common ports are listed below. _Before 1.18, this was combined with `SMTP_ADDR` under the name `HOST`._
658+
- 25: insecure SMTP
659+
- 465: SMTP Secure
660+
- 587: StartTLS
661+
- `USE_CLIENT_CERT`: **false**: Use client certificate for TLS/SSL.
662+
- `CLIENT_CERT_FILE`: **custom/mailer/cert.pem**: Client certificate file.
663+
- `CLIENT_KEY_FILE`: **custom/mailer/key.pem**: Client key file.
664+
- `FORCE_TRUST_SERVER_CERT`: **false**: If set to `true`, completely ignores server certificate validation errors. This option is unsafe. Consider adding the certificate to the system trust store instead.
660665
- `USER`: **\<empty\>**: Username of mailing user (usually the sender's e-mail address).
661666
- `PASSWD`: **\<empty\>**: Password of mailing user. Use \`your password\` for quoting if you use special characters in the password.
662-
- Please note: authentication is only supported when the SMTP server communication is encrypted with TLS (this can be via `STARTTLS`) or `HOST=localhost`. See [Email Setup]({{< relref "doc/usage/email-setup.en-us.md" >}}) for more information.
663-
- `SEND_AS_PLAIN_TEXT`: **false**: Send mails as plain text.
664-
- `SKIP_VERIFY`: **false**: Whether or not to skip verification of certificates; `true` to disable verification.
665-
- **Warning:** This option is unsafe. Consider adding the certificate to the system trust store instead.
666-
- **Note:** Gitea only supports SMTP with STARTTLS.
667-
- `USE_CERTIFICATE`: **false**: Use client certificate.
668-
- `CERT_FILE`: **custom/mailer/cert.pem**
669-
- `KEY_FILE`: **custom/mailer/key.pem**
667+
- Please note: authentication is only supported when the SMTP server communication is encrypted with TLS (this can be via `STARTTLS`) or SMTP host is localhost. See [Email Setup]({{< relref "doc/usage/email-setup.en-us.md" >}}) for more information.
668+
- `ENABLE_HELO`: **true**: Enable HELO operation.
669+
- `HELO_HOSTNAME`: **(retrieved from system)**: HELO hostname.
670+
- `FROM`: **\<empty\>**: Mail from address, RFC 5322. This can be just an email address, or the "Name" \<[email protected]\> format.
671+
- `ENVELOPE_FROM`: **\<empty\>**: Address set as the From address on the SMTP mail envelope. Set to `<>` to send an empty address.
670672
- `SUBJECT_PREFIX`: **\<empty\>**: Prefix to be placed before e-mail subject lines.
671-
- `MAILER_TYPE`: **smtp**: \[smtp, sendmail, dummy\]
672-
- **smtp** Use SMTP to send mail
673-
- **sendmail** Use the operating system's `sendmail` command instead of SMTP.
674-
This is common on Linux systems.
675-
- **dummy** Send email messages to the log as a testing phase.
676-
- Note that enabling sendmail will ignore all other `mailer` settings except `ENABLED`,
677-
`FROM`, `SUBJECT_PREFIX` and `SENDMAIL_PATH`.
678-
- Enabling dummy will ignore all settings except `ENABLED`, `SUBJECT_PREFIX` and `FROM`.
679-
- `SENDMAIL_PATH`: **sendmail**: The location of sendmail on the operating system (can be
680-
command or full path).
681-
- `SENDMAIL_ARGS`: **_empty_**: Specify any extra sendmail arguments. (NOTE: you should be aware that email addresses can look like options - if your `sendmail` command takes options you must set the option terminator `--`)
673+
- `SENDMAIL_PATH`: **sendmail**: The location of sendmail on the operating system (can be command or full path).
674+
- `SENDMAIL_ARGS`: **\<empty\>**: Specify any extra sendmail arguments. (NOTE: you should be aware that email addresses can look like options - if your `sendmail` command takes options you must set the option terminator `--`)
682675
- `SENDMAIL_TIMEOUT`: **5m**: default timeout for sending email through sendmail
683676
- `SENDMAIL_CONVERT_CRLF`: **true**: Most versions of sendmail prefer LF line endings rather than CRLF line endings. Set this to false if your version of sendmail requires CRLF line endings.
684677
- `SEND_BUFFER_LEN`: **100**: Buffer length of mailing queue. **DEPRECATED** use `LENGTH` in `[queue.mailer]`
678+
- `SEND_AS_PLAIN_TEXT`: **false**: Send mails only in plain text, without HTML alternative.
685679

686680
## Cache (`cache`)
687681

0 commit comments

Comments
 (0)