chore(deps): bump github.com/emersion/go-smtp from 0.20.2 to 0.21.0 (#1888)

* chore(deps): bump github.com/emersion/go-smtp from 0.20.2 to 0.21.0

Bumps [github.com/emersion/go-smtp](https://github.com/emersion/go-smtp) from 0.20.2 to 0.21.0.
- [Release notes](https://github.com/emersion/go-smtp/releases)
- [Commits](https://github.com/emersion/go-smtp/compare/v0.20.2...v0.21.0)

---
updated-dependencies:
- dependency-name: github.com/emersion/go-smtp
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* fix(reporter/email): use DialStartTLS instead of StartTLS

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: MaineK00n <mainek00n.1229@gmail.com>
This commit is contained in:
dependabot[bot]
2024-04-05 17:41:41 +09:00
committed by GitHub
parent 867bf63bb2
commit 3cdd2e10d0
5 changed files with 52 additions and 23 deletions

View File

@@ -9,6 +9,7 @@ import (
type SMTPConf struct {
SMTPAddr string `toml:"smtpAddr,omitempty" json:"-"`
SMTPPort string `toml:"smtpPort,omitempty" valid:"port" json:"-"`
TLSMode string `toml:"tlsMode,omitempty" json:"-"`
TLSInsecureSkipVerify bool `toml:"tlsInsecureSkipVerify,omitempty" json:"-"`
User string `toml:"user,omitempty" json:"-"`
Password string `toml:"password,omitempty" json:"-"`
@@ -51,6 +52,11 @@ func (c *SMTPConf) Validate() (errs []error) {
if c.SMTPPort == "" {
errs = append(errs, xerrors.New("email.smtpPort must not be empty"))
}
switch c.TLSMode {
case "", "None", "STARTTLS", "SMTPS":
default:
errs = append(errs, xerrors.New(`email.tlsMode accepts ["", "None", "STARTTLS", "SMTPS"]`))
}
if len(c.To) == 0 {
errs = append(errs, xerrors.New("email.To required at least one address"))
}

2
go.mod
View File

@@ -17,7 +17,7 @@ require (
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/d4l3k/messagediff v1.2.2-0.20190829033028-7e0a312ae40b
github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21
github.com/emersion/go-smtp v0.20.2
github.com/emersion/go-smtp v0.21.0
github.com/google/go-cmp v0.6.0
github.com/google/subcommands v1.2.0
github.com/google/uuid v1.6.0

4
go.sum
View File

@@ -487,8 +487,8 @@ github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a h1:mATvB/9r/3gvcej
github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM=
github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21 h1:OJyUGMJTzHTd1XQp98QTaHernxMYzRaOasRir9hUlFQ=
github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21/go.mod h1:iL2twTeMvZnrg54ZoPDNfJaJaqy0xIQFuBdrLsmspwQ=
github.com/emersion/go-smtp v0.20.2 h1:peX42Qnh5Q0q3vrAnRy43R/JwTnnv75AebxbkTL7Ia4=
github.com/emersion/go-smtp v0.20.2/go.mod h1:qm27SGYgoIPRot6ubfQ/GpiPy/g3PaZAVRxiO/sDUgQ=
github.com/emersion/go-smtp v0.21.0 h1:ZDZmX9aFUuPlD1lpoT0nC/nozZuIkSCyQIyxdijjCy0=
github.com/emersion/go-smtp v0.21.0/go.mod h1:qm27SGYgoIPRot6ubfQ/GpiPy/g3PaZAVRxiO/sDUgQ=
github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g=
github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=

View File

@@ -10,9 +10,10 @@ import (
sasl "github.com/emersion/go-sasl"
smtp "github.com/emersion/go-smtp"
"golang.org/x/xerrors"
"github.com/future-architect/vuls/config"
"github.com/future-architect/vuls/models"
"golang.org/x/xerrors"
)
// EMailWriter send mail
@@ -89,37 +90,58 @@ type emailSender struct {
}
func (e *emailSender) sendMail(smtpServerAddr, message string) (err error) {
var c *smtp.Client
var auth sasl.Client
emailConf := e.conf
//TLS Config
tlsConfig := &tls.Config{
ServerName: emailConf.SMTPAddr,
InsecureSkipVerify: emailConf.TLSInsecureSkipVerify,
}
switch emailConf.SMTPPort {
case "465":
//New TLS connection
c, err = smtp.DialTLS(smtpServerAddr, tlsConfig)
if err != nil {
return xerrors.Errorf("Failed to create TLS connection to SMTP server: %w", err)
var c *smtp.Client
switch emailConf.TLSMode {
case "":
switch emailConf.SMTPPort {
case "465":
c, err = smtp.DialTLS(smtpServerAddr, tlsConfig)
if err != nil {
return xerrors.Errorf("Failed to create TLS connection to SMTP server: %w", err)
}
defer c.Close()
default:
c, err = smtp.Dial(smtpServerAddr)
if err != nil {
return xerrors.Errorf("Failed to create connection to SMTP server: %w", err)
}
defer c.Close()
if ok, _ := c.Extension("STARTTLS"); ok {
c, err = smtp.DialStartTLS(smtpServerAddr, tlsConfig)
if err != nil {
return xerrors.Errorf("Failed to create STARTTLS connection to SMTP server: %w", err)
}
defer c.Close()
}
}
default:
case "None":
c, err = smtp.Dial(smtpServerAddr)
if err != nil {
return xerrors.Errorf("Failed to create connection to SMTP server: %w", err)
}
}
defer c.Close()
if err = c.Hello("localhost"); err != nil {
return xerrors.Errorf("Failed to send Hello command: %w", err)
}
if ok, _ := c.Extension("STARTTLS"); ok {
if err := c.StartTLS(tlsConfig); err != nil {
return xerrors.Errorf("Failed to STARTTLS: %w", err)
defer c.Close()
case "STARTTLS":
c, err = smtp.DialStartTLS(smtpServerAddr, tlsConfig)
if err != nil {
return xerrors.Errorf("Failed to create STARTTLS connection to SMTP server: %w", err)
}
defer c.Close()
case "SMTPS":
c, err = smtp.DialTLS(smtpServerAddr, tlsConfig)
if err != nil {
return xerrors.Errorf("Failed to create TLS connection to SMTP server: %w", err)
}
defer c.Close()
default:
return xerrors.New(`invalid TLS mode. accepts: ["", "None", "STARTTLS", "SMTPS"]`)
}
if ok, param := c.Extension("AUTH"); ok {

View File

@@ -127,6 +127,7 @@ func printConfigToml(ips []string) (err error) {
#[email]
#smtpAddr = "smtp.example.com"
#smtpPort = "587"
#tlsMode = "STARTTLS"
#tlsInsecureSkipVerify = false
#user = "username"
#password = "password"