diff --git a/README.ja.md b/README.ja.md index 1f24a11dc9..2e27d1463f 100644 --- a/README.ja.md +++ b/README.ja.md @@ -374,7 +374,7 @@ notifyUsers = ["@username"] [mail] smtpAddr = "smtp.gmail.com" -smtpPort = "465" +smtpPort = "587" user = "username" password = "password" from = "from@address.com" @@ -455,7 +455,7 @@ host = "172.31.4.82" ``` [mail] smtpAddr = "smtp.gmail.com" - smtpPort = "465" + smtpPort = "587" user = "username" password = "password" from = "from@address.com" diff --git a/README.md b/README.md index d1e5819cdc..1140e04bae 100644 --- a/README.md +++ b/README.md @@ -373,7 +373,7 @@ notifyUsers = ["@username"] [mail] smtpAddr = "smtp.gmail.com" -smtpPort = "465" +smtpPort = "587" user = "username" password = "password" from = "from@address.com" @@ -457,7 +457,7 @@ You can customize your configuration using this template. ``` [mail] smtpAddr = "smtp.gmail.com" - smtpPort = "465" + smtpPort = "587" user = "username" password = "password" from = "from@address.com" diff --git a/commands/discover.go b/commands/discover.go index 9e66c55ebc..92d147cd67 100644 --- a/commands/discover.go +++ b/commands/discover.go @@ -100,7 +100,7 @@ notifyUsers = ["@username"] [mail] smtpAddr = "smtp.gmail.com" -smtpPort = "465" +smtpPort = "587" user = "username" password = "password" from = "from@address.com" diff --git a/glide.lock b/glide.lock index 442bbc2b35..022ec975d9 100644 --- a/glide.lock +++ b/glide.lock @@ -118,6 +118,4 @@ imports: - unix - name: gopkg.in/alexcesaro/quotedprintable.v3 version: 2caba252f4dc53eaf6b553000885530023f54623 -- name: gopkg.in/gomail.v2 - version: 81ebce5c23dfd25c6c67194b37d3dd3f338c98b1 devImports: [] diff --git a/glide.yaml b/glide.yaml index 015240a5dd..afc3e18e9c 100644 --- a/glide.yaml +++ b/glide.yaml @@ -35,4 +35,3 @@ import: - package: golang.org/x/net subpackages: - context -- package: gopkg.in/gomail.v2 diff --git a/report/mail.go b/report/mail.go index 34cd3febde..caa92adc39 100644 --- a/report/mail.go +++ b/report/mail.go @@ -18,13 +18,14 @@ along with this program. If not, see . package report import ( - "crypto/tls" "fmt" - "strconv" + "net" + "net/mail" + "net/smtp" + "strings" "github.com/future-architect/vuls/config" "github.com/future-architect/vuls/models" - "gopkg.in/gomail.v2" ) // MailWriter send mail @@ -33,37 +34,53 @@ type MailWriter struct{} func (w MailWriter) Write(scanResults []models.ScanResult) (err error) { conf := config.Conf for _, s := range scanResults { - m := gomail.NewMessage() - m.SetHeader("From", conf.Mail.From) - m.SetHeader("To", conf.Mail.To...) - m.SetHeader("Cc", conf.Mail.Cc...) + to := strings.Join(conf.Mail.To[:], ", ") + cc := strings.Join(conf.Mail.Cc[:], ", ") + mailAddresses := append(conf.Mail.To, conf.Mail.Cc...) + if _, err := mail.ParseAddressList(strings.Join(mailAddresses[:], ", ")); err != nil { + return fmt.Errorf("Failed to parse mail addresses: %s", err) + } subject := fmt.Sprintf("%s%s %s", conf.Mail.SubjectPrefix, s.ServerInfo(), s.CveSummary(), ) - m.SetHeader("Subject", subject) + + headers := make(map[string]string) + headers["From"] = conf.Mail.From + headers["To"] = to + headers["Cc"] = cc + headers["Subject"] = subject + + var message string + for k, v := range headers { + message += fmt.Sprintf("%s: %s\r\n", k, v) + } var body string if body, err = toPlainText(s); err != nil { return err } - m.SetBody("text/plain", body) - port, _ := strconv.Atoi(conf.Mail.SMTPPort) - d := gomail.NewPlainDialer( - conf.Mail.SMTPAddr, - port, - conf.Mail.User, - conf.Mail.Password, - ) + message += "\r\n" + body - d.TLSConfig = &tls.Config{ - InsecureSkipVerify: true, - } + smtpServer := net.JoinHostPort(conf.Mail.SMTPAddr, conf.Mail.SMTPPort) + + err := smtp.SendMail( + smtpServer, + smtp.PlainAuth( + "", + conf.Mail.User, + conf.Mail.Password, + conf.Mail.SMTPAddr, + ), + conf.Mail.From, + conf.Mail.To, + []byte(message), + ) - if err := d.DialAndSend(m); err != nil { - panic(err) + if err != nil { + return fmt.Errorf("Failed to send mails: %s", err) } } return nil