暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

How To send email From a shell on linux

原创 Anbob 2012-12-19
609
usually,we do not want to setup an email serve,but just  want to send an email  from a Linux Shell script easily   when got  any  alert or exptions.then let's know what happend with the event on the Host,then to solve this problem.
ssmtp is quite easy to configure.the following was  configuration ssmtp on centos5(or  redhat el5)
[oracle@ggsdb ~]$ lsb_release -a
LSB Version:    :core-4.0-amd64:core-4.0-ia32:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-
ia32:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-ia32:printing-4.0-noarch
Distributor ID: CentOS
Description:    CentOS release 5.6 (Final)
Release:        5.6
Codename:       Final
1,download and install epel, addition yum repository
[root@ggsdb ~]# wget dl.iuscommunity.org/pub/ius/stable/CentOS/5/x86_64/epel-release-5-4.noarch.rpm
如果此链接失效,请自己去 http://rpm.pbone.net 上搜索
[root@ggsdb ~]# rpm -ivh epel-release-5-4.noarch.rpm
2, yum install ssmtp(be)
[root@ggsdb ~]# yum -y install ssmtp

3, edit the ssmtp configuration file.
[root@ggsdb ~]# cd /etc/ssmtp
[root@ggsdb ssmtp]# cp ssmtp.conf ssmtp.conf_bak
[root@ggsdb ssmtp]# vi ssmtp.conf
Update file with the following settings:
mailhub=smtp.mail.anbob.com
RewriteDomain=mail.anbob.com
Hostname=mail.anbob.com
AuthUser=zhangweizhao@mail.anbob.com
AuthPass=123456
4,configure the Aliases,default Sender show root@mail.anbob.com, sender show robot@mail.anbob.com affected by alias
[root@ggsdb ~]# vi  /etc/ssmtp/revaliases
root:Robot@mail.anbob.com:smtp.mail.anbob.com:25

5, make sure you disable Sendmail
Move or replace the sendmail and thencreate a symbolic link for sSMTP to sendmail with authentication
[root@ggsdb ~]# mkdir /root/.bakup
[root@ggsdb ~]# mv /usr/sbin/sendmail       /root/.bakup/
[root@ggsdb ~]# which ssmtp
/usr/sbin/ssmtp
[root@ggsdb ~]# ln -s /usr/sbin/ssmtp      /usr/sbin/sendmail
Before we start using sSMTP lets stop the sendmail which is default installed on all Linux distribution.
[root@ggsdb ~]# service sendmail stop
[root@ggsdb ~]# chkconfig –levels 2345 sendmail off

6,Now, you can use mail / mailx command to send email messages.ou can test settings using
following syntax:
[root@ggsdb ~]# echo "This is a test" | mail -s "Test" zhangweizhao@mail.anbob.com
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论