Skip to content

Commit

Permalink
Merge pull request #614 from AlexZip85/postee-for-enterprise
Browse files Browse the repository at this point in the history
Integration | Email | SMTP HELO check rejects "localhost"
  • Loading branch information
elad-da authored Oct 17, 2023
2 parents fda9d75 + 51dcf36 commit cae2ed7
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 18 deletions.
1 change: 1 addition & 0 deletions cfg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ outputs:
user: # Mandatory. E.g :[email protected]"
password: # Optional. Specify Jira user API key. Used only for Jira Cloud
token: # Optional. Specify Jira user Personal Access Token. Used only for Jira Server/Data Center
client-host-name: # Optional: setting the local client name instead of `localhost`
project-key: # Mandatory. Specify the JIRA product key
tls-verify: false
board: # Optional. Specify the Jira board name to open tickets on
Expand Down
1 change: 1 addition & 0 deletions data/integrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type OutputSettings struct {
Recipients []string `json:"recipients,omitempty"`
Sender string `json:"sender,omitempty"`
Token string `json:"token,omitempty"`
ClientHostName string `json:"client-host-name,omitempty"`
UseMX bool `json:"use-mx,omitempty"`
InstanceName string `json:"instance,omitempty"`
SizeLimit int `json:"size-limit,omitempty"`
Expand Down
74 changes: 64 additions & 10 deletions outputs/email.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package outputs

import (
"crypto/tls"
"errors"
"fmt"
"net"
Expand All @@ -24,15 +25,16 @@ var (
)

type EmailOutput struct {
Name string
User string
Password string
Host string
Port int
Sender string
Recipients []string
UseMX bool
sendFunc func(addr string, a customsmtp.Auth, from string, to []string, msg []byte) error
Name string
User string
Password string
Host string
Port int
Sender string
Recipients []string
ClientHostName string
UseMX bool
sendFunc func(addr string, a customsmtp.Auth, from string, to []string, msg []byte) error
}

func (email *EmailOutput) GetType() string {
Expand Down Expand Up @@ -63,12 +65,64 @@ func (email *EmailOutput) Init() error {
email.Sender = email.User
}

email.sendFunc = customsmtp.SendMail
if email.ClientHostName != "" {
log.Logger.Infof("Action %q uses a custom client name %q instead of `localhost`", email.Name, email.ClientHostName)
email.sendFunc = email.sendEmailWithCustomClient
} else {
email.sendFunc = customsmtp.SendMail
}

log.Logger.Infof("Successfully initialized email output %s", email.Name)
return nil
}

func (email *EmailOutput) sendEmailWithCustomClient(addr string, a customsmtp.Auth, from string, to []string, msg []byte) error {
log.Logger.Infof("Sending an email via Custom client for action %q", email.Name)

c, err := customsmtp.Dial(addr)
if err != nil {
return err
}
defer c.Close()

if err := c.Hello(email.ClientHostName); err != nil {
return err
}

if ok, _ := c.Extension("STARTTLS"); ok {
config := &tls.Config{ServerName: email.Host}
if err = c.StartTLS(config); err != nil {
return err
}
}
if a != nil {
if err = c.Auth(a); 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()
}

func (email *EmailOutput) Terminate() error {
log.Logger.Debug("Email output terminated")
return nil
Expand Down
17 changes: 9 additions & 8 deletions router/builders.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,15 @@ func buildSlackOutput(sourceSettings *data.OutputSettings, aqua string) *outputs

func buildEmailOutput(sourceSettings *data.OutputSettings) *outputs.EmailOutput {
return &outputs.EmailOutput{
Name: sourceSettings.Name,
User: sourceSettings.User,
Password: sourceSettings.Password,
Host: sourceSettings.Host,
Port: sourceSettings.Port,
Sender: sourceSettings.Sender,
Recipients: sourceSettings.Recipients,
UseMX: sourceSettings.UseMX,
Name: sourceSettings.Name,
User: sourceSettings.User,
Password: sourceSettings.Password,
Host: sourceSettings.Host,
Port: sourceSettings.Port,
Sender: sourceSettings.Sender,
Recipients: sourceSettings.Recipients,
ClientHostName: sourceSettings.ClientHostName,
UseMX: sourceSettings.UseMX,
}
}

Expand Down

0 comments on commit cae2ed7

Please sign in to comment.