LINUX下通过外部SMTP发邮件

方式一

修改/etc/mail.rc,增加一下类似N行,指定外部的smtp服务器地址、帐号密码等。

# vi /etc/mail.rc  
set from=123456@qq.com
set smtp=smtp.qq.com  
set smtp-auth-user=123456
set smtp-auth-password=sbsbsbsb
set smtp-auth=login  

然后通过命令来发送邮件

echo hello word | mail -s " title" 654321@qq.com

方式二

安装Postfix :

yum install postfix mail cyrus-sasl-* -y

配置Postfix:

vi /etc/postfix/main.cf

(Postfix主要配置文件,再其末尾添加以下配置)

#指定默认的邮件发送服务器
relayhost = [smtp.163.com]:25
#激活sasl认证
smtp_sasl_auth_enable = yes
#指定sasl密码配置文件
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
#非匿名登录
smtp_sasl_security_options = noanonymous
#指定认证类型 (提示:需要yum安装cyrus-sasl-*组件,否则发邮件时会报错:no mechanism available)
smtp_sasl_type = cyrus
#linux用户与发件人的对应关系配置文件
sender_canonical_maps = hash:/etc/postfix/sender_canonical 

vi /etc/postfix/sasl_passwd

(邮箱账号和密码文件,每行一个。 创建好后需要使用postmap命令使配置文件生效)

[smtp.163.com]:25 guang384@163.com:my163Password

postmap /etc/postfix/sasl_passwd

vi /etc/postfix/sender_canonical

(linux用户和发件人对应关系,每行一个)

root guang384@163.com

postmap /etc/postfix/sender_canonical

重启Postfix:

service postfix restart

尝试发送邮件:

echo "hello world" |mail -s test guang384@qq.com

(可以用 mailq 命令查看发送队列,清空mailq队列 : postsuper -d ALL )

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值