]> source.dussan.org Git - gitea.git/commitdiff
Allow mail with self-signed certificates
authorUnknwon <joe2010xtmf@163.com>
Thu, 9 Oct 2014 22:08:07 +0000 (18:08 -0400)
committerUnknwon <joe2010xtmf@163.com>
Thu, 9 Oct 2014 22:08:07 +0000 (18:08 -0400)
gogs.go
modules/mailer/mailer.go
templates/.VERSION

diff --git a/gogs.go b/gogs.go
index 250333f39a66637c70dea07ab102a8cec6cb980d..f38256220ff2858f29d16689d67f6cec917606dc 100644 (file)
--- a/gogs.go
+++ b/gogs.go
@@ -17,7 +17,7 @@ import (
        "github.com/gogits/gogs/modules/setting"
 )
 
-const APP_VER = "0.5.5.1008 Beta"
+const APP_VER = "0.5.5.1009 Beta"
 
 func init() {
        runtime.GOMAXPROCS(runtime.NumCPU())
index 6397ccc41aa8311c7bfa3ebc0f34f4ce9ec23473..758792a3515913de9f9837931862da1eed233de1 100644 (file)
@@ -5,7 +5,9 @@
 package mailer
 
 import (
+       "crypto/tls"
        "fmt"
+       "net"
        "net/smtp"
        "strings"
 
@@ -64,6 +66,53 @@ func processMailQueue() {
        }
 }
 
+// sendMail allows mail with self-signed certificates.
+func sendMail(hostAddressWithPort string, auth smtp.Auth, from string, recipients []string, msgContent []byte) error {
+       client, err := smtp.Dial(hostAddressWithPort)
+       if err != nil {
+               return err
+       }
+
+       host, _, _ := net.SplitHostPort(hostAddressWithPort)
+       tlsConn := &tls.Config{
+               InsecureSkipVerify: true,
+               ServerName:         host,
+       }
+       if err = client.StartTLS(tlsConn); err != nil {
+               return err
+       }
+
+       if auth != nil {
+               if err = client.Auth(auth); err != nil {
+                       return err
+               }
+       }
+
+       if err = client.Mail(from); err != nil {
+               return err
+       }
+
+       for _, rec := range recipients {
+               if err = client.Rcpt(rec); err != nil {
+                       return err
+               }
+       }
+
+       w, err := client.Data()
+       if err != nil {
+               return err
+       }
+       if _, err = w.Write([]byte(msgContent)); err != nil {
+               return err
+       }
+
+       if err = w.Close(); err != nil {
+               return err
+       }
+
+       return client.Quit()
+}
+
 // Direct Send mail message
 func Send(msg *Message) (int, error) {
        log.Trace("Sending mails to: %s", strings.Join(msg.To, "; "))
@@ -85,7 +134,7 @@ func Send(msg *Message) (int, error) {
                num := 0
                for _, to := range msg.To {
                        body := []byte("To: " + to + "\r\n" + content)
-                       err := smtp.SendMail(setting.MailService.Host, auth, msg.From, []string{to}, body)
+                       err := sendMail(setting.MailService.Host, auth, msg.From, []string{to}, body)
                        if err != nil {
                                return num, err
                        }
@@ -96,7 +145,7 @@ func Send(msg *Message) (int, error) {
                body := []byte("To: " + strings.Join(msg.To, ";") + "\r\n" + content)
 
                // send to multiple emails in one message
-               err := smtp.SendMail(setting.MailService.Host, auth, msg.From, msg.To, body)
+               err := sendMail(setting.MailService.Host, auth, msg.From, msg.To, body)
                if err != nil {
                        return 0, err
                } else {
index 194ec58029be56f260a99451a86b7c70288f417c..35a9c242838bd563a5aa84b8710773ca71268b74 100644 (file)
@@ -1 +1 @@
-0.5.5.1008 Beta
\ No newline at end of file
+0.5.5.1009 Beta
\ No newline at end of file