Shell使用sendemail发送邮件脚本

原文地址:http://www.zixuephp.net/article-400.html

       shell发送邮件,这里要介绍的是sendemail工具,通过这个工具连接第三方的smtp服务器,进行邮件的发送,简单高效。在web场景中可以方便的被调用shell,轻松进行邮件的发送。

        sendemail是一个轻量级,功能强大的邮件发送客户端(不接收邮件),sendemail不是sendmail。

一、sendemail安装

    yum安装sendemail会自动安装好相关依赖软件

yum install -y sendemail

install sendemail.png

二、sendemail的使用说明

    1.查看sendemail帮助

/usr/bin/sendemail --help

    2.sendemail基本参数

/usr/bin/sendemail

-f  [email protected] 发件人邮箱地址

-t  [email protected]  收件人邮箱

-s  smtp.qq.com  发件人邮箱的smtp服务器

-u  '标题'  邮件的主题

-o message-content-type=html  邮件内容的格式为html,也可以是text

-o message-charset=utf8  邮件内容编码

-xu [email protected]  发件人账号

-xp 123456  发件人密码

-m  '邮件内容'  邮件的内容

  3.发送邮件命令demo:

sendemail -f [email protected] -t "[email protected]" -s smtp.qq.com -u '测试主题' -o message-content-type=html -o message-charset=utf8 -xu [email protected] -xp 123456 -m "邮件内容"

三、sendemail.sh shell发送邮件脚本

  1.编写脚本

vim sendemail.sh
#!/bin/bash
#script name : sendemail.sh
account='[email protected]'
password='123456'
to=$1
subject=$2
content=$3
sendemail -f $account -t $to -s smtp.doov.com.cn -u $subject -o message-content-type=html -o message-charset=utf8 -xu $account -xp $password -m $content

  2.设置脚本执行权限

chmod +x sendemail.sh

  3.执行脚本,传入参数,发送邮件

./sendemail.sh [email protected] 测试主题 测试内容

sendemail send success.png

发送成功后会提示 Email was sent successfully! 如果是在php中可以使用system("sendemail.sh '[email protected]' '测试主题' '测试内容', $status);

猜你喜欢

转载自blog.csdn.net/boonya/article/details/89457436
今日推荐