Working on ignoring certs

pull/146/head
Jordan Wright 2016-02-11 12:53:00 -06:00
parent 7f381f861e
commit bbe97f5602
2 changed files with 16 additions and 20 deletions

View File

@ -10,6 +10,7 @@ type SMTP struct {
Username string `json:"username,omitempty"` Username string `json:"username,omitempty"`
Password string `json:"password,omitempty" sql:"-"` Password string `json:"password,omitempty" sql:"-"`
FromAddress string `json:"from_address"` FromAddress string `json:"from_address"`
IgnoreCertErrors bool `json:"ignore_cert_errors"`
} }
// ErrFromAddressNotSpecified is thrown when there is no "From" address // ErrFromAddressNotSpecified is thrown when there is no "From" address

View File

@ -143,10 +143,6 @@ func SendTestEmail(s *models.SendTestEmailRequest) error {
Subject: s.Template.Subject, Subject: s.Template.Subject,
From: s.SMTP.FromAddress, From: s.SMTP.FromAddress,
} }
var auth smtp.Auth
if s.SMTP.Username != "" && s.SMTP.Password != "" {
auth = smtp.PlainAuth("", s.SMTP.Username, s.SMTP.Password, strings.Split(s.SMTP.Host, ":")[0])
}
f, err := mail.ParseAddress(s.SMTP.FromAddress) f, err := mail.ParseAddress(s.SMTP.FromAddress)
if err != nil { if err != nil {
Logger.Println(err) Logger.Println(err)
@ -190,7 +186,7 @@ func SendTestEmail(s *models.SendTestEmailRequest) error {
e.Subject = string(subjBuff.Bytes()) e.Subject = string(subjBuff.Bytes())
e.To = []string{s.Email} e.To = []string{s.Email}
Logger.Printf("Sending Email to %s\n", s.Email) Logger.Printf("Sending Email to %s\n", s.Email)
err = e.Send(s.SMTP.Host, auth) err = sendMail(e, s.SMTP)
if err != nil { if err != nil {
Logger.Println(err) Logger.Println(err)
// For now, let's split the error and return // For now, let's split the error and return
@ -204,7 +200,7 @@ func SendTestEmail(s *models.SendTestEmailRequest) error {
// sendEmail is a copy of the net/smtp#SendMail function // sendEmail is a copy of the net/smtp#SendMail function
// that has the option to ignore TLS errors // that has the option to ignore TLS errors
// TODO: Find a more elegant way (maybe in the email lib?) to do this // TODO: Find a more elegant way (maybe in the email lib?) to do this
func sendMail(e email.Email, s models.SMTP, tlsConfig *tls.Config) error { func sendMail(e email.Email, s models.SMTP) error {
var auth smtp.Auth var auth smtp.Auth
if s.Username != "" && s.Password != "" { if s.Username != "" && s.Password != "" {
auth = smtp.PlainAuth("", s.Username, s.Password, strings.Split(s.Host, ":")[0]) auth = smtp.PlainAuth("", s.Username, s.Password, strings.Split(s.Host, ":")[0])
@ -239,18 +235,17 @@ func sendMail(e email.Email, s models.SMTP, tlsConfig *tls.Config) error {
return err return err
} }
defer c.Close() defer c.Close()
if err = c.Hello(); err != nil { if err = c.Hello("localhost"); err != nil {
return err return err
} }
// Use TLS if available // Use TLS if available
if ok, _ := c.Extension("STARTTLS"); ok { if ok, _ := c.Extension("STARTTLS"); ok {
host, _, _ := net.SplitHostPort(s.Host) host, _, _ := net.SplitHostPort(s.Host)
/*
config := &tls.Config{ config := &tls.Config{
ServerName: host, ServerName: host,
InsecureSkipVerify: s.IgnoreCertErrors, InsecureSkipVerify: s.IgnoreCertErrors,
}*/ }
if err = c.StartTLS(tlsConfig); err != nil { if err = c.StartTLS(config); err != nil {
return err return err
} }
} }
@ -262,7 +257,7 @@ func sendMail(e email.Email, s models.SMTP, tlsConfig *tls.Config) error {
} }
} }
} }
if err = c.Mail(from); err != nil { if err = c.Mail(from.Address); err != nil {
return err return err
} }
for _, addr := range to { for _, addr := range to {