ssmtp skript


#!/bin/bash

# Set the email address to use for sending emails
EMAIL_ADDRESS="user@example.com"

# Set the list of passwords to try when sending emails
PASSWORDS=(password1 password2 password3)

# Set the SMTP server and port to use for sending emails
SMTP_SERVER="smtp.example.com"
SMTP_PORT=587

# Set the recipients of the email
RECIPIENTS="recipient1@example.com recipient2@example.com"

# Set the subject and message body of the email
SUBJECT="Example Email"
MESSAGE="This is an example email sent using ssmtp"

# Loop through the list of passwords, trying each one until the email is successfully sent
for password in "${PASSWORDS[@]}"; do
# Set the password for the current iteration
echo "AuthUser=$EMAIL_ADDRESS" > ~/.ssmtp/ssmtp.conf
echo "AuthPass=$password" >> ~/.ssmtp/ssmtp.conf
echo "mailhub=$SMTP_SERVER:$SMTP_PORT" >> ~/.ssmtp/ssmtp.conf
echo "UseSTARTTLS=YES" >> ~/.ssmtp/ssmtp.conf

# Send the email and store the output in a variable
EMAIL_OUTPUT=$(echo -e "To: $RECIPIENTS\nSubject: $SUBJECT\n\n$MESSAGE" | ssmtp $RECIPIENTS)

# Check if the email was successfully sent
if [[ $EMAIL_OUTPUT == *"250 2.0.0 OK"* ]]; then
# Email was successfully sent
break
else
# Email was not successfully sent, try the next password
continue
fi
done

# Check if the email was successfully sent with any of the passwords
if [[ $EMAIL_OUTPUT != *"250 2.0.0 OK"* ]]; then
# Email was not successfully sent with any of the passwords
echo "Error: Failed to send email with any of the provided passwords"
else
# Email was successfully sent
echo "Success: Email was sent successfully"
fi

Dieser Beitrag wurde unter bash, Linux veröffentlicht. Setze ein Lesezeichen auf den Permalink.