Added UI checkbox... working on sendmail function

pull/146/head
Jordan Wright 2016-02-09 22:08:41 -06:00
parent a0a8a7b8ad
commit c436bdb514
3 changed files with 93 additions and 1 deletions

3
static/css/main.css vendored
View File

@ -448,3 +448,6 @@ table.dataTable thead .sorting_desc:after {
.timeline-event-table{ .timeline-event-table{
display:none; display:none;
} }
.tooltip-inner {
width:300px !important;
}

View File

@ -96,7 +96,10 @@
<br /> <br />
<label class="control-label" for="smtp_server">Password:</label> <label class="control-label" for="smtp_server">Password:</label>
<input type="password" class="form-control" placeholder="Password" value="" name="password"> <input type="password" class="form-control" placeholder="Password" value="" name="password">
<br /> <div class="checkbox checkbox-primary">
<input id="ignore_cert_errors" type="checkbox" checked>
<label for="ignore_cert_errors">Ignore Certificate Errors <i class="fa fa-question-circle" data-toggle="tooltip" data-placement="right" title="Ignore common certificate errors such as self-signed certs (exposes you to MiTM attacks - use carefully!)"></i></label>
</div>
<button type="button" data-toggle="modal" data-target="#sendTestEmailModal" class="btn btn-primary"><i class="fa fa-envelope"></i> Send Test Email</button> <button type="button" data-toggle="modal" data-target="#sendTestEmailModal" class="btn btn-primary"><i class="fa fa-envelope"></i> Send Test Email</button>
</div> </div>
</div> </div>

View File

@ -2,8 +2,10 @@ package worker
import ( import (
"bytes" "bytes"
"crypto/tls"
"errors" "errors"
"log" "log"
"net"
"net/mail" "net/mail"
"net/smtp" "net/smtp"
"os" "os"
@ -198,3 +200,87 @@ func SendTestEmail(s *models.SendTestEmailRequest) error {
} }
return err return err
} }
// sendEmail is a copy of the net/smtp#SendMail function
// that has the option to ignore TLS errors
// 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 {
var auth smtp.Auth
if s.Username != "" && s.Password != "" {
auth = smtp.PlainAuth("", s.Username, s.Password, strings.Split(s.Host, ":")[0])
}
// Taken from the email library
// Merge the To, Cc, and Bcc fields
to := make([]string, 0, len(e.To)+len(e.Cc)+len(e.Bcc))
to = append(append(append(to, e.To...), e.Cc...), e.Bcc...)
for i := 0; i < len(to); i++ {
addr, err := mail.ParseAddress(to[i])
if err != nil {
return err
}
to[i] = addr.Address
}
// Check to make sure there is at least one recipient and one "From" address
if e.From == "" || len(to) == 0 {
return errors.New("Must specify at least one From address and one To address")
}
from, err := mail.ParseAddress(e.From)
if err != nil {
return err
}
msg, err := e.Bytes()
if err != nil {
return err
}
// Taken from the standard library
// https://github.com/golang/go/blob/master/src/net/smtp/smtp.go#L300
c, err := smtp.Dial(s.Host)
if err != nil {
return err
}
defer c.Close()
if err = c.Hello(); err != nil {
return err
}
// Use TLS if available
if ok, _ := c.Extension("STARTTLS"); ok {
host, _, _ := net.SplitHostPort(s.Host)
/*
config := &tls.Config{
ServerName: host,
InsecureSkipVerify: s.IgnoreCertErrors,
}*/
if err = c.StartTLS(tlsConfig); err != nil {
return err
}
}
if auth != nil {
if ok, _ := c.Extension("AUTH"); ok {
if err = c.Auth(auth); err != nil {
return err
}
}
}
if err = c.Mail(from); err != nil {
return err
}
for _, addr := range to {
if err = c.Rcpt(addr); err != nil {
return err
}
}
w, err := c.Data()
if err != nil {
return err
}
_, err = w.Write(msg)
if err != nil {
return err
}
err = w.Close()
if err != nil {
return err
}
return c.Quit()
}