summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
author无闻 <u@gogs.io>2015-02-28 22:25:48 -0500
committer无闻 <u@gogs.io>2015-02-28 22:25:48 -0500
commit3db80f2c555316b92b2be0cb0a53adb37eca910a (patch)
tree1698c52fbe2aea31c48eda76909783d94794413e /modules
parenta6a2f59d1da927a1fae9d009f58e63881c4c029a (diff)
parent2692d4aa49deec286058cd2196da379a97534787 (diff)
downloadgitea-3db80f2c555316b92b2be0cb0a53adb37eca910a.tar.gz
gitea-3db80f2c555316b92b2be0cb0a53adb37eca910a.zip
Merge pull request #943 from diseaz/mailer-client-cert
Use client certificate for SMTP over TLS
Diffstat (limited to 'modules')
-rw-r--r--modules/mailer/mailer.go8
-rw-r--r--modules/setting/setting.go25
2 files changed, 23 insertions, 10 deletions
diff --git a/modules/mailer/mailer.go b/modules/mailer/mailer.go
index fc6ec2fa86..74a3fca578 100644
--- a/modules/mailer/mailer.go
+++ b/modules/mailer/mailer.go
@@ -78,6 +78,14 @@ func sendMail(settings *setting.Mailer, recipients []string, msgContent []byte)
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))
if err != nil {
return err
diff --git a/modules/setting/setting.go b/modules/setting/setting.go
index 6db43b16b3..fd07c17f23 100644
--- a/modules/setting/setting.go
+++ b/modules/setting/setting.go
@@ -451,11 +451,13 @@ func newSessionService() {
// Mailer represents mail service.
type Mailer struct {
- Name string
- Host string
- From string
- User, Passwd string
- SkipVerify bool
+ Name string
+ Host string
+ From string
+ User, Passwd string
+ SkipVerify bool
+ UseCertificate bool
+ CertFile, KeyFile string
}
type OauthInfo struct {
@@ -483,11 +485,14 @@ func newMailService() {
}
MailService = &Mailer{
- Name: sec.Key("NAME").MustString(AppName),
- Host: sec.Key("HOST").String(),
- User: sec.Key("USER").String(),
- Passwd: sec.Key("PASSWD").String(),
- SkipVerify: sec.Key("SKIP_VERIFY").MustBool(),
+ Name: sec.Key("NAME").MustString(AppName),
+ Host: sec.Key("HOST").String(),
+ User: sec.Key("USER").String(),
+ Passwd: sec.Key("PASSWD").String(),
+ 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)
log.Info("Mail Service Enabled")