如何使用sendEmail如何发送邮件到邮箱

posts - 10,&
comments - 25,&
trackbacks - 0
1.安装sendEmail2.发送 用你的邮箱aaa 发送邮件到& sendEmail -s
-f aaa -t bbb -u hello -m "测试数据" -a /test/databases/tm.sh -xu&aaa -xp&&&&&xxxx -o tls=auto&&& & -s
指定服务器域名,邮件发送一般通过SMTP协议实现,其域名一般为,qq邮箱服务器& -f &指定发送邮箱地址& -t &指定目的邮箱地址& -u hello 邮件标题& -m "XXX" 邮件内容,发送文件 mail.txt 换用-o message-file=mail.txt& -xu aaa 指定邮箱用户名& -xp password 指定发送邮箱的密码& -o tls=auto 加密方式,在none,tls,ssl自动选择& 邮件中粘贴福建 -a&文件1 |&文件2&
&re: 命令行下发送邮件sendEmail
&table&&tr&&td&123123&/td&&/tr&&/table&&&&&&&
你恨一个人是因为你爱他;你喜欢一个人,是因为他身上有你没有的;你讨厌一个人是因为他身上有你有的东西;你经常在别人面前批评某人,其实潜意识中是想接近他。
22232425262728123456789101112131415161718192021222324252627282930311234
一些简单系统,留着备用!
java技术网站
平时常去的网站
吸血鬼日记第三季
阅读排行榜
评论排行榜magicsa 的BLOG
用户名:magicsa
文章数:228
评论数:37
访问量:312337
注册日期:
51CTO推荐博文
:转载时请以超链接形式标明文章原始出处和作者信息及
nagios发警告邮件是采用本机的smtp服务,可以查看commands.cfg中关于发邮件的命令的定义,使用本机的mail命令,这就需要开启本机的smtp服务,为了安全可以在防火墙上设置拒绝其他的机器连本机的25号端口
现在我们的网络里面有一个邮件服务器,所以要求使用这台现有的邮件服务器,不开启本机的smtp服务,这就需要重新定义命令使用第三方软件sendEmail.
首先我们当然要在邮件服务器上新建一个账户用来做发邮件的账户
这里邮件服务器的地址为
用来发邮件的帐号
SMTP验证的用户名&nagios&密码&p#3isoda
以下就来介绍一下sendEmail这个软件的使用.
sendEmail的主页
软件十分小,是一个通过命令来发smtp邮件的程序.安装也十分简单(查看其README文件即可).
解压缩tar &zxvf sendEmail-v1.55.tar.gz
cd sendEmail-v1.55
将可执行程序复制cp sendEmail /usr/local/bin
然后给确认确实它具有执行权限
ll /usr/local/bin/sendEmail
-rwxr-xr-x 1 root root
14:23 /usr/local/bin/sendEmail
这样程序就装好了,使用也很简单.直接运行sendEmail就会显示详细的用法
先看一个典型的例子
/usr/local/bin/sendEmail &f&&&t&&&s
&u &from nagios& &xu nagios &xp p#3isoda &m happy
-f&表示发送者的邮箱
-t&表示接收者的邮箱
-s&表示SMTP服务器的域名或者ip
-u&表示邮件的主题
-xu&表示SMTP验证的用户名
-xp&表示SMTP验证的密码(注意,这个密码貌似有限制,例如我用d!5neyland就不能被正确识别)
-m&表示邮件的内容
如果你不带-m参数的话,就会提示你自行输入
Reading message body from STDIN because the &-m& option was not used.
If you are manually typing in a message:
- First line must be received within 60 seconds.
- End manual input with a CTRL-D on its own line
输入完成后使用CTRL-D来结束
当然我们也可以将一个文件的内容作为邮件的正文发出去的
那么就可以使用:
cat&文件名&| /usr/local/bin/sendEmail &f&&&t&&&s
&u &from nagios& &xu nagios &xp p#3isoda
有关sendEmail的用法就讲到这里
既然nagios要使用sendEmail来发警告邮件,那么就要修改commands.cfg中关于发邮件的命令的定义,我们现在来修改notify-by-email这个命令,如下(注意其中粗体的部分)
# 'notify-by-email' command definition
define command{
&&&&&&&&command_name&&&&notify-by-email
&&&&&&&&command_line&&&&/usr/bin/printf &%b& &***** Nagios 2.9 *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$& |&/usr/local/bin/sendEmail -f&&-t $CONTACTEMAIL$ -s
-u &** $NOTIFICATIONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **& -xu nagios -xp p#3isoda
注:其实sendEmail是一个十分有用的程序,我们在这个地方用了它,其实别的地方也可以用,典型的好处就是你不需要每台机器都装sendmail,开启smtp服务.直接用现成的一台邮件服务器就行了,这无疑很大的加强了系统的安全性,也节约了资源.
了这篇文章
类别:┆阅读(0)┆评论(0)
16:44:58 17:11:00 10:32:27 10:07:32Categories:
被监控机添加用户
groupadd nagios
useradd -g nagios -d /usr/local/nagios -s /sbin/nologin nagios
被监控机安装plugin
wget http://nchc.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.13.tar.gz
tar zxf nagios-plugins-1.4.13.tar.gz
cd nagios-plugins-1.4.13
./configure --with-nagios-user=nagios --with-nagios-group=nagios --prefix=/usr/local/nagios --with-ping-command=&/bin/ping& --with-mysql=/opt/mysql
make install
#查看播件文件是否已安装在这个目录
ls /usr/local/nagios/libexec
被监控机安装NRPE
wget http://nchc.dl.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz
tar zxvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure --prefix=/usr/local/nagios
make install-plugin
make install-daemon
make install-daemon-config
chown -R nagios:nagios /usr/local/nagios
配置 NRPE:
vi /usr/local/nagios/etc/nrpe.cfg
allowed_hosts=127.0.0.1,192.168.1.91
#Nagios监控机的地址或域名
修改/etc/hosts.allow增加监控机ip
echo 'nrpe:192.168.1.91' && /etc/hosts.allow
启动 NRPE 守护进程:
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
可以将此命令加入 /etc/rc.local ,以便开机自动启动。
echo &/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d& && /etc/rc.local
检查 NRPE 是否正常:
在被监控机上
/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
查看相应的端口:netstat -an |grep 5666
防火墙开启5666 允许局域网IP或固定IP连接
在监控主机上
/usr/local/nagios/libexec/check_nrpe -H $目标主机地址
都应该可以输出 NRPE 的版本: NRPE v2.12
检查可监控的服务
在被监控端的 nrpe.cfg 文件中,可以看到这样的配置:
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
这是用来检查 CPU 负载的。
如果需要自定参数则使用下面命令
command[check_load]=/usr/local/nagios/libexec/check_load -w $ARG1$ -c $ARG2$
并开启dont_blame_nrpe =1
开启参数将会带来一定的安全风险
被监控机重启nrpe
ps aux|grep nrpe
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
监控机设置
在监控机commands.cfg 添加nrpe的定义
# 'check_nrpe ' command definition
define command{
&& & & &command_name check_nrpe
&& & & &command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
增加hostA.cfg
在/usr/local/nagios/etc/objects/ 目录下新建文件:hostA.cfg
把A.cfg添加到nagios主机:
echo “cfg_file=/usr/local/nagios/etc/objects/hostA.cfg” >> /usr/local/nagios/etc/nagios.cfg
如果要再添加B机器方法炮制就可以了
define host{
use& & & & & & & & & &generic-server& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & &
&& & & &host_name& & & & & & &A
&& & & &alias& & & & & & & & &A
&& & & &address& & & & & & & &A 的IP
define service{
use& &generic-service&
host_name& A
service_description load
check_command& check_nrpe!check_load
#使用自定参数
#check_command check_nrpe!check_load!6.0,5.0,4.0!15.0,8.0,6.0
重启监控机nagios
service nagios reload
访问http://localhost/nagios就可以看到新增的机器了
如何修改nrpe端口
被监控机nrpe.cfg修改server_port为15666
/usr/local/nagios/libexec/check_nrpe -p 15666 -H 127.0.0.1
server_port=15666
监控机commands.cfg增加-p 15666
define command{
&& & & &command_name check_nrpe
&& & & &command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -p 15666 -c $ARG1$
重启nagios就可以了
Connection refused or timed out
检查nrpe 端口
检查nrpe.cfg中allowed_hosts是否包含监控机ip地址
检查/etc/hosts.allow文件中监控机ip地址nrpe:192.168.1.91
检查iptables
开放5666端口
iptables -L
iptables -A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 5666 -j ACCEPT
iptables -L
service iptables save
service iptables restart
NRPE: Unable to read output
1.检查客户端nrpe的权限是否可读,可被nagios执行。
2.检查nrpe.cfg里面commands命令路径是否正确。
CHECK_NRPE: Error – Could not complete SSL handshake.
1.查看防火墙
2.nrpe.cfg中授权ip
3./etc/hosts.allow中授权ip
Related Posts ( )
Posted in , .
Stay in touch with the conversation, subscribe to the .
Continuing the Discussion
About C1G军火库
关注互联网、网页设计、Web开发、服务器运维优化、项目管理、网站运营、网站安全…
2015年三月
9101112131415
16171819202122
23242526272829使用邮件监控ssh登陆用户shell脚本
会员登录:
站内搜索:
使用邮件监控ssh登陆用户shell脚本
使用邮件监控ssh登陆用户shell脚本
作者: 文章来源: 点击数: 更新时间: 13:44:51
  wget /uploads/softs/sendEmail-v1.56.tar.gz
  tar xvf sendEmail-v1.56.tar.gz
  mv sendEmail-v1.56 sendEmail
  vi /etc/ssh/sshrc
  #!/bin/sh
  user=$USER
  ip=${SSH_CLIENT%% *}
  if [ "$user" != "root" ] || [ "$ip" != "192.168.2.88" ]
  /home/shell/sendEmail/sendEmail -f XXX@XXX -t XXX@XXX -s smtp.XXX -u "查看谁登陆###192.168.2.4###" -xu USER -xp PASSWD -m "###time:`date +%Y-%m-%d`###.###user:$USER@`hostname`###.###ClientIP:${SSH_CLIENT%% *}###"
  chmod +x /etc/ssh/sshrc
  ###############简单讲解####################
  $USER获取到登陆通过ssh的用户名
  ${SSH_CLIENT%% *}取到登陆通过ssh的用户名的IP
  if [ "$user" != "root" ] || [ "$ip" != "192.168.2.88" ]使用或来判断来源,是否发邮件报警
  ###########################################
  测试:
  1 使用root并且IP为192.168.2.88,看是否发邮件报警
  测试结果是:没有邮件报警
  2 使用root并且IP为192.168.2.87,看是否报警
  测试结果是:邮件发送报警
  查看邮箱:
  这个脚本对于ssh安全监控非常有用,非法登陆都可以时时了解情况,及时保护服务器安全
文章录入:小吕&&&&责任编辑:洋葱头&
上一篇文章: 下一篇文章:
【字体: 】【】【】【】【】【】
  网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
站长邮箱:
联系电话:86-10-
Copyright &   北京华安普特网络科技有限公司 版权所有Python发送邮件 - 东升红日辉万里,明泽润物彻古今 - ITeye技术网站
博客分类:
一、直接调用命令行发送邮件(以及shell中sendEmail)
问题:主题为中文时乱码
主题乱码,网上找了很多,基本上可以确认是头文件编码的问题,通过对主题进行base64编码可以解决这个问题,实现如下:
# 发送email,username用户名,subject主题,text内容
def send_email(self,username,subject,text):
# 邮件内容为utf-8格式
text = text.encode('utf-8')
# 主题需要进行base64编码在转成utf8,注意后面这个strip,否则又出现一个换行符
subject = "=?UTF-8?B?%s?=" % base64.encodestring(subject).strip()
cmd = "/usr/bin/sendEmail -f
-o message-charset=utf-8 -u \"%s\"
-m \"%s\" " % (username,subject,text)
rt = os.popen(cmd).read().split()
return True
except Exception,e:
return False
直接用shell发送邮件的代码如下
subject=`echo -n 任务异常 | base64`
test_time=
sendEmail -f
-o message-charset=utf-8 -u "=?UTF-8?B?${subject}?="
-m "已经存在任务,${test_time}的任务取消进行"
补充:& 正文的换行符是
如果是ssh调用其他的邮件服务器来发邮件,命令要ssh命令要用双引号括起来,否则换行字符不识别 ssh root@**** "sendemai -o ...."
二、使用SMTP协议发送邮件
newusers = ';'
text = '测试邮件'
mail_host = ''
mail_user = 'xxx_service'
mail_user_full = 'xxx_'
mail_pwd = '密码'
mail_bcc = ''
msg = MIMEText(text,'base64', 'utf-8')
msg['From'] = mail_user_full
msg['Subject'] = subject
msg['To'] = newusers
msg['Cc'] = newccs
msg['Bcc'] = ''
s = smtplib.SMTP()
s.connect(mail_host,'25')
s.login(mail_user,mail_pwd)
#send mail
print newusers
print newccs
print msg.as_string()
邮件人发送和抄送统一放在一起发送,需要在上面的标头信息中进行区分
s.sendmail(mail_user_full,newusers.split(';')+newccs.split(';')+mail_bcc.split(";"),msg.as_string())
print 'success'
# print rt
return True
except Exception,e:
# print 'email error'
return False
hotsunshine
浏览: 189504 次
来自: 北京
非常感谢,我的也是磁盘满了导致的问题,顺便分享下查看磁盘的命令 ...
vikki 写道沙发先。楼主,这些代码例子你都运行过吗?运行过 ...
沙发先。楼主,这些代码例子你都运行过吗?
vikki 写道在rails 3.2.14中 request
在rails 3.2.14中 request env 已经不是 ...}

我要回帖

更多关于 sendemail 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信