mutt发送邮件

发布时间:2021-07-16 17:15:33 阅读:1846次

转:http://hi.baidu.com/rushm/item/c395e6a9e3d49d746dd455a9
http://blog.163.com/a12333a_li/blog/static/87594285201212042332551/
http://cache.baiducontent.com/c?m=9d78d513d9961de84fede53f5e578971182497624fc0d0643e87d21684642a563712f4cc27351174c4b3787077ad5e5d9ae74673207724a0eabc9f3cd9ac92597fdb6663671cf74514c419dedc3626d657924d98af0e90cae733e3b9a2d5c82325dd22726df4f19f1d404ac535b65273f4a7ea55081e56e7ad7b24a6126029e8731eeb12eee0456904d0b0804b4cb47b8d3e0c93af3fb63918a813af1e192643&p=c9759a46d7c209ea0fb1ce2d0214c6&newp=b47dc64ad49d5fff57ee957f52518a231610db2151d7db1421ca&user=baidu&fm=sc&query=GNU+SASL%3A+SASL+%BF%E2%D6%D0%B3%F6%CF%D6+Base+64+%B1%E0%C2%EB%B4%ED%CE%F3&qid=&p1=1

http://www.111cn.net/sys/nginx/45576.htm
http://storysky.blog.51cto.com/628458/293005
http://ddupnow.iteye.com/blog/566083

echo "mutt发送邮件" | mutt -s "测试"  test115@me.com
 2002  mutt -s "测试" -a /etc/hosts -a /etc/apple ufo@sina.com < /tmp/imax.txt
 2006  echo "testmail" | mutt -s "测试"  test115@me.com
 2017  mutt -s 'test' test115@me.com < /var/www/html/hello.php
 2018  mutt -s 'test' test115@me.com -a /var/www/html/hello.php
root@test:~# echo "qq mail 内容" | mutt -s 'test' 183367466@qq.com -a /var/www/html/hello.php

/etc/Muttrc
138 set sendmail="/usr/bin/msmtp"
139 set use_from=yes
140 set realname="test"
141 set from=test115@163.com
142 set envelope_from=yes
143
144 #-----------------如有编码问题可以尝试在后面加入----
145 set charset="utf-8"
146 #set send_charset="gb2312"
147 set send_charset="utf-8"
148 set locale = "zh_CN.UTF-8"
149 set content_type = "text/html\;charset=utf-8"

~/.msmtprc
  1 account default
  2 host smtp.163.com
  3 from mozatmonitor@163.com
  4 #auth login    
  5 auth plain //这里重要,不能不能发送到除了163的其它邮箱
  6 user test115
  7 password 123456
  8 logfile ~/.msmtp.log


在ubuntu下用sendmail有点问题,主题发出去老为空。

干脆安装mutt和msmtp,通过163的邮件系统发邮件。

sudo apt-get install mutt,另外需要安装msmtp,一个发邮件的小工具,sudo apt-get install msmtp

配置mutt

 1、在 /etc/Muttrc 文件里最后加入5行

set sendmail="/usr/bin/msmtp"
set use_from=yes
set realname="mozatmonitor"     ---》发件人显示昵称
set from=mozatmonitor@163.com     --》发件人地址
set envelope_from=yes

-----------------如有编码问题可以尝试在后面加入----

set charset="utf-8"
#set send_charset="gb2312"
set send_charset="utf-8"
set locale = "zh_CN.UTF-8"
set content_type = "text/html\;charset=utf-8"

 

2、编辑~/.msmtprc,如果这个文件不存在就创建一个,要录属于当前用户和群组,该文件需要600权限,如果不是600权限会无法使用。

account default
host smtp.163.com               ---->邮件服务器地址
from mozatmonitor@163.com   
auth login                           ------> 认证方式用最傻的login
user mozatmonitor
password kkkkkk                    ----->kkkkkk替换成密码
logfile ~/.msmtp.log

 

 

发送:

mutt -s "主题" foo@sina.com.cn -a 附件.txt <邮件内容.txt

多联系人多附件:

MailList=`cat list.txt`

/usr/bin/mutt  -s "主题" $MailList -a 附件1 -a 附件2  < hello.txt

 

 ##报警发邮件

1、扔脚本在后台导入数据(这个脚本包含计算脚本运行时间):nohup ./import.sh &
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
   
mozat@DellR410-DB4:~$ cat import.sh  
#!/bin/bash
   
BEGINTIME=`date +"%Y-%m-%d %H:%M:%S"`
   
/usr/local/mysql-5.5.15/bin/mysql  -h 127.0.0.1 -P 3335  -uxxx -pxxxxxx < /home/mozat/xxx.sql
   
ENDTIME=`date +"%Y-%m-%d %H:%M:%S"`
begin_data=`date -d  "$BEGINTIME" +%s`    #把当前时间转化为Linux时间
end_data=`date -d  "$ENDTIME" +%s`
spendtime=`expr $end_data - $begin_data`  #计算2个时间的差
   
   
echo "it takes $spendtime sec for dump the data directory"
echo "it takes $spendtime sec for dump the data directory" >/tmp/dump184_3335mofs2.txt

 2、在crontab中每分钟跑监控脚本,如果发现跑完,就发邮件给139邮件,这样手机就会收到短信。
1
2
3
4
5
6
7
8
9
10
11
   
mozat@DellR410-DB4:~$ crontab -l
*/1 * * * * /bin/sh  /home/mozat/operation/xx/sendmail.sh
mozat@DellR410-DB4:~$ cat  /home/mozat/operation/xx/sendmail.sh
#!/bin/bash
  
counter=`ps -ef | grep import.sh | grep -v grep |wc -l`
if [ $counter -eq 0 ]; then
        /usr/bin/mutt -s "back is finished" 13xxxxx@139.com </home/mozat/operation/xx/hello.txt
else
        echo "the  backup is running now."
fi

如有问题,可以QQ搜索群1028468525加入群聊,欢迎一起研究技术

支付宝 微信

有疑问联系站长,请联系QQ:QQ咨询

转载请注明:mutt发送邮件 出自老鄢博客 | 欢迎分享