forked from gitea/gitea
1
0
Fork 0

Merge pull request #943 from diseaz/mailer-client-cert

Use client certificate for SMTP over TLS
This commit is contained in:
无闻 2015-02-28 22:25:48 -05:00
commit 3db80f2c55
3 changed files with 27 additions and 10 deletions

View File

@ -105,6 +105,10 @@ SUBJECT = %(APP_NAME)s
HOST = HOST =
; Do not verify the certificate of the server. Only use this for self-signed certificates ; Do not verify the certificate of the server. Only use this for self-signed certificates
SKIP_VERIFY = SKIP_VERIFY =
; Use client certificate
USE_CERTIFICATE = false
CERT_FILE = custom/mailer/cert.pem
KEY_FILE = custom/mailer/key.pem
; Mail from address, RFC 5322. This can be just an email address, or the "Name" <email@example.com> format ; Mail from address, RFC 5322. This can be just an email address, or the "Name" <email@example.com> format
FROM = FROM =
; Mailer user name and password ; Mailer user name and password

View File

@ -78,6 +78,14 @@ func sendMail(settings *setting.Mailer, recipients []string, msgContent []byte)
ServerName: host, ServerName: host,
} }
if settings.UseCertificate {
cert, err := tls.LoadX509KeyPair(settings.CertFile, settings.KeyFile)
if err != nil {
return err
}
tlsconfig.Certificates = []tls.Certificate{cert}
}
conn, err := net.Dial("tcp", net.JoinHostPort(host, port)) conn, err := net.Dial("tcp", net.JoinHostPort(host, port))
if err != nil { if err != nil {
return err return err

View File

@ -456,6 +456,8 @@ type Mailer struct {
From string From string
User, Passwd string User, Passwd string
SkipVerify bool SkipVerify bool
UseCertificate bool
CertFile, KeyFile string
} }
type OauthInfo struct { type OauthInfo struct {
@ -488,6 +490,9 @@ func newMailService() {
User: sec.Key("USER").String(), User: sec.Key("USER").String(),
Passwd: sec.Key("PASSWD").String(), Passwd: sec.Key("PASSWD").String(),
SkipVerify: sec.Key("SKIP_VERIFY").MustBool(), SkipVerify: sec.Key("SKIP_VERIFY").MustBool(),
UseCertificate: sec.Key("USE_CERTIFICATE").MustBool(),
CertFile: sec.Key("CERT_FILE").String(),
KeyFile: sec.Key("KEY_FILE").String(),
} }
MailService.From = sec.Key("FROM").MustString(MailService.User) MailService.From = sec.Key("FROM").MustString(MailService.User)
log.Info("Mail Service Enabled") log.Info("Mail Service Enabled")