始创于2000年 股票代码:831685
咨询热线:0371-60135900 注册有礼 登录
  • 挂牌上市企业
  • 60秒人工响应
  • 99.99%连通率
  • 7*24h人工
  • 故障100倍补偿
您的位置: 网站首页 > 帮助中心>文章内容

linux下实现自动发送文本mail邮件的脚本

发布时间:  2012/8/10 15:01:45
 1. 安装msmtp

  luther@gliethttp:~$ sudo apt-get install msmtp

  2. 编辑配置脚本(~/.msmtprc是默认配置文件,也可以使用-C选项指定配置文件路径)

  luther@gliethttp:~$ vim msmtprc

  #添加如下内容

  defaults

  #logfile /home/luther/msmtp.log

  account luther_test

  host mail.gliethttp.cn

  from luther@gliethttp.cn

  auth off

  password 123456789

  account default : luther_test

  3. 去掉配置文件的执行权限-x

  luther@gliethttp:~$ chmod 600 msmtprc

  4. 好了,可以使用下面语句发送一个测试邮件到自己的邮箱了,或者在stdin上输入,然后ctrl+D

  可能文件中的部分数据会丢失,不怕,当我们安装mutt之后就一切正常了.

  luther@gliethttp:~$ msmtp luther@gliethttp.cn -C /home/luther/msmtprc < /vobs/tmp/log.c

  5. 接着安装mutt

  luther@gliethttp:~$ sudo apt-get install mutt

  6. 编辑配置脚本(~/.muttrc是默认配置文件,也可以使用-F选项指定配置文件路径)

  luther@gliethttp:~$ vim muttrc

  #添加如下内容

  set sendmail="/usr/bin/msmtp -C /home/luther/msmtprc"

  set use_from=yes

  set from=admin@gliethttp.cn

  set realname="测试admin"

  set editor="vim"

  7. 发送普通文本和文件内容

  luther@gliethttp:~$ echo "测试123abc" | mutt -F /home/luther/muttrc -s "邮件标题 - 测试" luther@gliethttp.cn

  luther@gliethttp:~$ mutt -F /home/luther/muttrc -s "邮件标题 - 测试" luther@gliethttp.cn < /etc/passwd

  8. 发送附件(-a选项用来添加附件,下面这个例子添加了passwd和resolv.conf这2个附件)

  luther@gliethttp:~$ echo "测试123abc" | mutt -F /home/luther/muttrc -s "邮件标题 - 测试" luther@gliethttp.cn -a /etc/passwd -a /etc/resolv.conf

  9. bcc地址和cc抄送地址发送,如果多个邮件地址,使用逗号分隔即可

  luther@gliethttp:~$ echo "测试123abc" | mutt -F /home/luther/muttrc -s "

  邮件标题 - 测试" luther@gliethttp.cn,luther.ge@163.com -b luther.ge@163.com,luther@gliethttp.cn -c   luther.ge@163.com,luther@gliethttp.cn


本文出自:亿恩科技【www.enkj.com】

服务器租用/服务器托管中国五强!虚拟主机域名注册顶级提供商!15年品质保障!--亿恩科技[ENKJ.COM]

  • 您可能在找
  • 亿恩北京公司:
  • 经营性ICP/ISP证:京B2-20150015
  • 亿恩郑州公司:
  • 经营性ICP/ISP/IDC证:豫B1.B2-20060070
  • 亿恩南昌公司:
  • 经营性ICP/ISP证:赣B2-20080012
  • 服务器/云主机 24小时售后服务电话:0371-60135900
  • 虚拟主机/智能建站 24小时售后服务电话:0371-60135900
  • 专注服务器托管17年
    扫扫关注-微信公众号
    0371-60135900
    Copyright© 1999-2019 ENKJ All Rights Reserved 亿恩科技 版权所有  地址:郑州市高新区翠竹街1号总部企业基地亿恩大厦  法律顾问:河南亚太人律师事务所郝建锋、杜慧月律师   京公网安备41019702002023号
      0
     
     
     
     

    0371-60135900
    7*24小时客服服务热线