Skip to content

Instantly share code, notes, and snippets.

@iCyLand
Last active November 9, 2023 10:29
Show Gist options
  • Save iCyLand/d9691e26a73192c3856cd542593a4b50 to your computer and use it in GitHub Desktop.
Save iCyLand/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="[email protected]"
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="[email protected]"
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 ssl-verify=ignore \
-S nss-config-dir=$NSS_DIR \
-a $FILEPATH \
$TO_EMAIL_ADDRESS
@aru303
Copy link

aru303 commented Jul 28, 2021

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

@iCyLand
Copy link
Author

iCyLand commented Jul 29, 2021

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
Copy link

uniuuu commented Jul 28, 2022

@iCyLand -S ssl-verify=ignore duplicated

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