在shell中使用sendmail发送邮件

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.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值