Last active
November 9, 2023 10:29
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
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 (☞゚ヮ゚)☞
@iCyLand -S ssl-verify=ignore
duplicated
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for your script
line 23 -- -S smtp=smtp://$SMTP_SERVER:SMTP_PORT \ to -S smtp=smtp://$SMTP_SERVER:$SMTP_PORT \