linux 使用SMTP代理发送邮件

    对于想在Linux下面发送邮件,而且自己又没有独立的域名主机,就不能向外部发送邮件。

因此可以用一下发放来解决这个问题,简言之就是利用Linux当做一个邮箱的客户端来登录已经存在的邮箱,比如126,163等等,用登陆的邮件来向外网发送邮件。
参考文档:
http://www.360doc.com/content/13/0109/19/5907545_259215174.shtml
http://blog.163.com/zsmasheng@126/blog/static/4305595020136244484769/

测试环境:

#uname -a
Linux 2.6.32-358.el6.x86_64 #1 SMP Fri Feb 22 00:31:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

方法一:

yum install -y mailx

主要是修改/etc/mail.rc文件
编辑 /etc/mail.rc文件,添加以下内容:

set [email protected]                登陆邮箱的账号,如[email protected]
set smtp=smtp.XXX.com               邮箱的smtp服务器,如smtp.126.com
set [email protected]      邮箱的用户名,比如[email protected]
set smtp-auth-password=Password     邮件的密码
set smtp-auth=login                 认证方式:登陆

关闭系统的sendmail,postfix

#service sendmail stop
#service postfix stop
#chkconfig sendmail off
#chkconfig postfix off

发送测试邮件:

echo "hello" | mail -s "Title" [email protected]


根据网速、运营商、SMTP的情况不同,邮件发送将有延迟现象。


方法二: 运用 mutt 和 msmtp 代理发送邮件

yum -y install mutt msmtp

编辑 /etc/Murrtc 添加如下代码:

set sendmail="/usr/bin/msmtp"    msmtp命令的绝对路径
set use_from=yes   
set realname="Test"              自定义显示的发件人
set from="[email protected]"        发件箱地址
set envelope_from=yes

编辑 /root/.msmtprc添加如下代码

account default
host smtp.126.com                  所用邮箱的smtp地址
from [email protected]                发件箱地址
auth login                         登录,根据smtp支持的认证方式修改
user wangyi                        邮件账号,不包括@后面的域名
password wangyi                    发件箱密码
logfile /var/log/msmtp.log         日志文件路径
service postfix restart
echo 'This is a test mail' | mutt -s 'Test' -a /tmp/test.txt [email protected]


你可能感兴趣的:(smtp,postfix,sendmail,Mutt,msmtp)