Extended configuration to allow to set the hostname of the smtp client.

The value  configured by 'clienthostname' is used by the gomail client
as hostname in the HELO command.
This commit is contained in:
harald 2019-11-06 17:57:05 +01:00
parent f39d409f1c
commit 5203727773
3 changed files with 12 additions and 0 deletions

View file

@ -7,6 +7,8 @@ const (
DefaultOnlyRecipients = false DefaultOnlyRecipients = false
// DefaultSkipVerify controls wether to skip SSL verification for the SMTP server // DefaultSkipVerify controls wether to skip SSL verification for the SMTP server
DefaultSkipVerify = false DefaultSkipVerify = false
// DefaultClientHostname is the client hostname used in the HELO command sent to the SMTP server
DefaultClientHostname = "localhost"
) )
// DefaultSubject is the default subject template to use for the email // DefaultSubject is the default subject template to use for the email

View file

@ -84,6 +84,13 @@ func main() {
Usage: "attachment filename(s)", Usage: "attachment filename(s)",
EnvVar: "PLUGIN_ATTACHMENTS", EnvVar: "PLUGIN_ATTACHMENTS",
}, },
cli.StringFlag{
Name: "clienthostname",
Value: DefaultClientHostname,
Usage: "smtp client hostname",
EnvVar: "EMAIL_CLIENTHOSTNAME,PLUGIN_CLIENTHOSTNAME",
},
// Drone environment // Drone environment
// Repo // Repo
@ -381,6 +388,7 @@ func run(c *cli.Context) error {
Body: c.String("template.body"), Body: c.String("template.body"),
Attachment: c.String("attachment"), Attachment: c.String("attachment"),
Attachments: c.StringSlice("attachments"), Attachments: c.StringSlice("attachments"),
ClientHostname: c.String("clienthostname"),
}, },
} }

View file

@ -91,6 +91,7 @@ type (
Body string Body string
Attachment string Attachment string
Attachments []string Attachments []string
ClientHostname string
} }
Plugin struct { Plugin struct {
@ -133,6 +134,7 @@ func (p Plugin) Exec() error {
if p.Config.SkipVerify { if p.Config.SkipVerify {
dialer.TLSConfig = &tls.Config{InsecureSkipVerify: true} dialer.TLSConfig = &tls.Config{InsecureSkipVerify: true}
} }
dialer.LocalName = p.Config.ClientHostname
closer, err := dialer.Dial() closer, err := dialer.Dial()
if err != nil { if err != nil {