0
0
Fork 0
mirror of https://github.com/go-gitea/gitea synced 2024-11-25 13:13:02 +01:00

Fix "forcing" client certificate for SMTP

This commit is contained in:
Dmitry Azhichakov 2015-02-13 10:33:55 +03:00
parent 8a6c86644e
commit 3aaf292ba8
3 changed files with 21 additions and 13 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 = true
; 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

@ -72,15 +72,17 @@ func sendMail(settings *setting.Mailer, recipients []string, msgContent []byte)
return err return err
} }
cert, err := tls.LoadX509KeyPair(settings.CertFile, settings.KeyFile)
if err != nil {
return err
}
tlsconfig := &tls.Config{ tlsconfig := &tls.Config{
InsecureSkipVerify: settings.SkipVerify, InsecureSkipVerify: settings.SkipVerify,
ServerName: host, ServerName: host,
Certificates: []tls.Certificate{cert}, }
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))

View file

@ -451,6 +451,7 @@ type Mailer struct {
From string From string
User, Passwd string User, Passwd string
SkipVerify bool SkipVerify bool
UseCertificate bool
CertFile, KeyFile string CertFile, KeyFile string
} }
@ -479,13 +480,14 @@ func newMailService() {
} }
MailService = &Mailer{ MailService = &Mailer{
Name: sec.Key("NAME").MustString(AppName), Name: sec.Key("NAME").MustString(AppName),
Host: sec.Key("HOST").String(), Host: sec.Key("HOST").String(),
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(),
CertFile: sec.Key("CERT_FILE").String(), UseCertificate: sec.Key("USE_CERTIFICATE").MustBool(),
KeyFile: sec.Key("KEY_FILE").String(), 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")