在shell中使用sendmail发送邮件

拓拔富
2023-12-01

script1

cat > sendmymail.sh

 

#!/bin/bash
/usr/sbin/sendmail -t <<EOF
From: Mail testing <abc@gmail.com>          
To: abc@gmail.com                                      
Cc: abc@gmail.com                                    
Bcc: abc@gmail.com                                  
Subject: mail testing                                          
----------------------------------                               
This is the mail content ...
---------------------------------
EOF

chmod u+x sendmymail.sh

./sendmymail.sh

script2

#!/bin/bash

curday=$1
msg=$2

echo "From: xxx@xxx.com" > .email.txt
echo "To: xxx@xxx.com;xxx@xxx.com" >> .email.txt

echo "MIME-Version: 1.0" >> .email.txt
echo "Content-Type: text/html" >> .email.txt
echo "Subject: [MapLBSLogDistcpAlarm] - $curday" >> .email.txt

echo "" >> .email.txt
echo "<html>" >> .email.txt
echo "<body>" >> .email.txt

echo "<br/>$msg<br/><br/><br/>" >> .email.txt
echo "host: `hostname`<br/>" >> .email.txt
echo "user: `whoami`<br/>" >> .email.txt
echo "path: `pwd`<br/>" >> .email.txt

echo "</body>" >> .email.txt
echo "</html>" >> .email.txt

cat .email.txt | /usr/sbin/sendmail -t

echo "send ok"
rm -rf .email.txt

man sendmailq
-t参数的含义

-t Read message for recipients. To:, Cc:, and Bcc: lines will be
scanned for recipient addresses. The Bcc: line will be deleted
before transmission.

 类似资料: