Skip to content

Instantly share code, notes, and snippets.

@ice-limited
Last active February 25, 2025 01:00
Show Gist options
  • Select an option

  • Save ice-limited/d9691e26a73192c3856cd542593a4b50 to your computer and use it in GitHub Desktop.

Select an option

Save ice-limited/d9691e26a73192c3856cd542593a4b50 to your computer and use it in GitHub Desktop.
Shell script send mail via mailx for authentication SMTP server and attachment file
#!/bin/sh
### option configuration
MESSAGE_BODY="Test mail"
EMAIL_SUBJECT="Testing Email from Shell Script with SMTP-01"
FROM_EMAIL_ADDRESS="noreply@sender.com"
FRIENDLY_NAME="NO Reply test"
SMTP_SERVER="smtp.sender.com"
SMTP_PORT="587"
SMTP_USER="User"
SMTP_PASS="Password"
###### for multi recipient please use space between address
TO_EMAIL_ADDRESS="recipient@example.com"
FILEPATH="attachmentfile.csv"
###### How to file NSS dir use command follow this comment - find / -name "cert*.db"
NSS_DIR="/etc/pki/nssdb/"
### execute section
echo $MESSAGE_BODY | mailx -v -s "$EMAIL_SUBJECT" \
-S smtp-use-starttls \
-S ssl-verify=ignore \
-S smtp-auth=login \
-S smtp=smtp://$SMTP_SERVER:$SMTP_PORT \
-S from="$FROM_EMAIL_ADDRESS($FRIENDLY_NAME)" \
-S smtp-auth-user=$SMTP_USER \
-S smtp-auth-password=$SMTP_PASS \
-S nss-config-dir=$NSS_DIR \
-a $FILEPATH \
$TO_EMAIL_ADDRESS
@aru303

aru303 commented Jul 28, 2021

Copy link
Copy Markdown

Thanks for your script
line 23 -- -S smtp=smtp://$SMTP_SERVER:SMTP_PORT \ to -S smtp=smtp://$SMTP_SERVER:$SMTP_PORT \

@ice-limited

Copy link
Copy Markdown
Author

Thanks for your script
line 23 -- -S smtp=smtp://$SMTP_SERVER:SMTP_PORT \ to -S smtp=smtp://$SMTP_SERVER:$SMTP_PORT \

Oh thank you for you correct me (☞゚ヮ゚)☞

@uniuuu

uniuuu commented Jul 28, 2022

Copy link
Copy Markdown

@iCyLand -S ssl-verify=ignore duplicated

@GTP95

GTP95 commented Feb 17, 2025

Copy link
Copy Markdown

Why many lines of the mailx command begin with -S? This seems to brek the script for me, as mailx complains about it being sn unrecognized option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment