Skip to content

Commit

Permalink
feat(sendSMTPEmail) support helo customization
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierCharuel committed Oct 9, 2024
1 parent fc7d43b commit 7372cc8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ export [email protected]
export POP_SMTP_PASSWORD=hunter2
```

#### Custom HELO

> **Note**:
> [Some SMTP relays](https://support.google.com/a/answer/2956491?hl=en&fl=1&sjid=11501593087205020993-NA) does not support `localhost` in the HELO CMD (which is the default pop behavior).
To configure HELO value, you can set the following environment variables.

```
export POP_SMTP_HELO=charm.sh
```

Or via the cli `pop -c charm.sh`|`pop --smtp.helo charm.sh`

### Environment

To avoid typing your `From: ` email address, you can also set the `POP_FROM`
Expand Down
1 change: 1 addition & 0 deletions email.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func sendSMTPEmail(to, cc, bcc []string, from, subject, body string, attachments
server.Password = smtpPassword
server.Host = smtpHost
server.Port = smtpPort
server.Helo = smtpHelo

// Set defaults for gmail.
if strings.HasSuffix(server.Username, gmailSuffix) {
Expand Down
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ const PopSMTPPassword = "POP_SMTP_PASSWORD" //nolint:gosec
// PopSMTPEncryption is the encryption type for the SMTP server if the user is using the SMTP delivery method.
const PopSMTPEncryption = "POP_SMTP_ENCRYPTION" //nolint:gosec

// PopSMTPHelo is the HELO sent to the SMTP server if the user is using the SMTP delivery method.
const PopSMTPHelo = "POP_SMTP_HELO"

// PopSMTPInsecureSkipVerify is whether or not to skip TLS verification for the
// SMTP server if the user is using the SMTP delivery method.
const PopSMTPInsecureSkipVerify = "POP_SMTP_INSECURE_SKIP_VERIFY"
Expand All @@ -67,6 +70,7 @@ var (
smtpEncryption string
smtpInsecureSkipVerify bool
resendAPIKey string
smtpHelo string
)

var rootCmd = &cobra.Command{
Expand Down Expand Up @@ -226,6 +230,8 @@ func init() {
rootCmd.Flags().BoolVarP(&smtpInsecureSkipVerify, "smtp.insecure", "i", envInsecureSkipVerify, "Skip TLS verification with SMTP server"+commentStyle.Render("($"+PopSMTPInsecureSkipVerify+")"))
envResendAPIKey := os.Getenv(ResendAPIKey)
rootCmd.Flags().StringVarP(&resendAPIKey, "resend.key", "r", envResendAPIKey, "API key for the Resend.com"+commentStyle.Render("($"+ResendAPIKey+")"))
envSMTPHelo := os.Getenv(PopSMTPHelo)
rootCmd.Flags().StringVarP(&smtpHelo, "smtp.helo", "c", envSMTPHelo, "Helo sent to the SMTP server"+commentStyle.Render("($"+PopSMTPHelo+")"))

rootCmd.CompletionOptions.HiddenDefaultCmd = true

Expand Down
Binary file added pop
Binary file not shown.

0 comments on commit 7372cc8

Please sign in to comment.