使用 sendmail 发送电子邮件

使用 sendmail 发送电子邮件

我正在使用一个通过邮件实用程序发送邮件的脚本,但现在我想使用 sendmail 发送邮件,有人可以帮助我吗,因为我无法从 sendmail 获得与从邮件中获得相同的结果。

#Email Settings
Message_Success="Application Backup generated successfully"
Message_Failure="Problem occured while generating Application Backup please verify"

Subject="Application Backup Status Mail"

Recipients="[email protected]"

#Check if Backup is complete
if [ -e "$Backup_File" ]; then
echo "Today's Backup File Exist's" >> $Log_File
echo "$Message_Success" | mail -s "$Subject" "$Recipients"
else
echo "Today's Backup File Not Found" >> $Log_File
echo "$Message_Failure" | mail -s "$Subject" "$Recipients"
fi

我弄清楚了一点,就在这里。但我在哪里可以定义电子邮件主题?

echo "$Message_Success" | sendmail -f [email protected] "$Recipients"

答案1

我会写

if [ -e "$Backup_File" ]; then
    echo "Today's Backup File Exist's" >> $Log_File
else
    echo "Today's Backup File Not Found" >> $Log_File
fi
{
    printf "To: %s\nSubject: %s\n\n" "$Recipients" "$Subject"
    if [ -e "$Backup_File" ]; then
        echo "$Message_Success"
    else
        echo "$Message_Failure"
    fi
} | /path/to/sendmail -oi -t -f [email protected] 

您正在编写带有标题的消息,并将其传递给 sendmail。该-t标志强制 sendmail 从消息中读取收件人。

相关内容