在Centos7下捣鼓邮件发送软件sendmail与postfix
2017-12-19 23:00
309 查看
虽然只是在整GITLAB过程中的一个小插曲,却意外的难搞,
花了我很多时间,网络上的各种教程与排错众说纷纭,看似简单的功能变得异常复杂。
邮件发送功能, 即MTA做为许多系统的必备,最常用的有sendmail与postfix两种。
我使用的是Centos7 minimal版,postfix是与系统一起安装进来的。
鉴于想更全面一些了解邮件发送软件,就从鼎鼎大名的sendmail开始入手捣鼓。
Sendmail
<=========================================
一. 安装sendmail
yum -y install sendmail sendmail-cf
二. 安装MTA功能测试用软件
yum -y install mailx php
三. 切换系统的邮件发送接口
alternatives --config mta
画面显示:
There are 2 programs which provide 'mta'.
Selection Command
-----------------------------------------------
+ 1 /usr/sbin/sendmail.postfix
* 2 /usr/sbin/sendmail.sendmail
Enter to keep the current selection[+], or type selection number: 2
输入2后回车即把MTA功能切换到sendmail上,+号会显示在sendmail的行头。
四. 配置sendmail
vi /etc/mail/sendmail.mc
DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl
把Addr的值从127.0.0.1修改为0.0.0.0,不限制使用MTA的IP。
m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
生成正式的配置文件。
五. 重启并测试功能
reboot -f
重启完成后确认MTA程序已经切换到sendmail
ps aux | grep sendmail
root 1003 0.0 0.2 88688 2280 ? Ss 10:40 0:00 sendmail: accepting connections
smmsp 1018 0.0 0.1 84120 1912 ? Ss 10:40 0:00 sendmail: Queue runner@01:00:00 for /var/spool/clientmqueue
root 1141 0.0 0.0 112660 968 pts/1 R+ 10:51 0:00 grep --color=auto sendmail
sendmail的相关进程已经启动
ps aux | grep postfix
root 1161 0.0 0.0 112660 968 pts/1 R+ 11:04 0:00 grep --color=auto postfix
postfix的相关进程都没有开启
用PHP函数发送邮件
php -a
在PHP的交互界面下输入以下函数
mail('test@sohu.com', "Test email content", "sendmail title", null, "-f testname@sendmail.com");
* 使用PHP接口做测试的好处是可以随意指定发送方的邮件地址,即mail函数的最后一个参数。
即使系统的hostname未设置也可以正常发送出邮件。
六. 使用linux的mail命令发送邮件
mail命令就没有使用自定义的邮件发送地址,而是使用HOSTNAME。
安装系统时由于没有对hostname做特别设置,HOSTNAME的值是默认的 localhost.localdomain
这样的邮件域名会被大多数邮箱如163,QQ拒收。
查看邮件发送log会发现以下错误
cat /var/log/maillog
dsn=4.1.8, stat=Deferred: 450 4.1.8 <root@localhost.localdomain>: Sender address rejected: Domain not found
修改HOSTNAME
vi /etc/hosts
在最后加上一行
192.168.2.108 intest.com
这里的IP地址是我跑sendmail虚拟机的IP,需根据实际情况设置
* 其实这个文件hosts只是用来设置本地路由表,但填上本机IP时,系统在启动初始化中查到本机IP在hosts中,
就会用hosts文件中对应的域名来设置HOSTNAME。
重新启动
reboot -f
重启后发现本地的DNS配置文件etc/resolv.conf 已经被自动更新。
内容变成 nameserver 192.168.2.1
<
96a7
strong>执行mail命令发送邮件[/b]
echo "test mail content"|mail -s "Mail title" test@sohu.com
==========================================>
Postfix
<=========================================
一. 切换系统的邮件发送接口
alternatives --config mta
* Postfix是Centos7系统默认自带。 也可以用命令
yum list installed | grep postfix 确认
选择postfix所在行的编号后回车
二. 重启并测试功能
reboot -f
重启后查看进程看到postfix相关的进程已经启动
ps aux | grep postfix
root 1093 0.0 0.2 89544 2172 ? Ss 08:55 0:00 /usr/libexec/postfix/master -w
postfix 1094 0.0 0.4 89648 4016 ? S 08:55 0:00 pickup -l -t unix -u
postfix 1095 0.0 0.4 89716 4044 ? S 08:55 0:00 qmgr -l -t unix -u
postfix 1237 0.0 0.4 89796 4072 ? S 09:08 0:00 cleanup -z -t unix -u
postfix 1238 0.0 0.4 89652 4024 ? S 09:08 0:00 trivial-rewrite -n rewrite -t unix -u
postfix 1239 0.0 0.4 89856 4272 ? S 09:08 0:00 smtp -t unix -u
root 1274 0.0 0.0 112660 972 pts/1 R+ 09:09 0:00 grep --color=auto postfix
系统的hostname已经在sendmail配置的第六步中完成了配置,这里就直接使用PHP与mail命令
两种方法做测试。
php -a
mail('test@sohu.com', "Test email No1", "postfix mail", null, "-f test@ccfst.com");
* php的mail函数可以随意指定发送地址
echo "test mail"|mail -s "postfix mail title" test@sohu.com
==========================================>
花了我很多时间,网络上的各种教程与排错众说纷纭,看似简单的功能变得异常复杂。
邮件发送功能, 即MTA做为许多系统的必备,最常用的有sendmail与postfix两种。
我使用的是Centos7 minimal版,postfix是与系统一起安装进来的。
鉴于想更全面一些了解邮件发送软件,就从鼎鼎大名的sendmail开始入手捣鼓。
Sendmail
<=========================================
一. 安装sendmail
yum -y install sendmail sendmail-cf
二. 安装MTA功能测试用软件
yum -y install mailx php
三. 切换系统的邮件发送接口
alternatives --config mta
画面显示:
There are 2 programs which provide 'mta'.
Selection Command
-----------------------------------------------
+ 1 /usr/sbin/sendmail.postfix
* 2 /usr/sbin/sendmail.sendmail
Enter to keep the current selection[+], or type selection number: 2
输入2后回车即把MTA功能切换到sendmail上,+号会显示在sendmail的行头。
四. 配置sendmail
vi /etc/mail/sendmail.mc
DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl
把Addr的值从127.0.0.1修改为0.0.0.0,不限制使用MTA的IP。
m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
生成正式的配置文件。
五. 重启并测试功能
reboot -f
重启完成后确认MTA程序已经切换到sendmail
ps aux | grep sendmail
root 1003 0.0 0.2 88688 2280 ? Ss 10:40 0:00 sendmail: accepting connections
smmsp 1018 0.0 0.1 84120 1912 ? Ss 10:40 0:00 sendmail: Queue runner@01:00:00 for /var/spool/clientmqueue
root 1141 0.0 0.0 112660 968 pts/1 R+ 10:51 0:00 grep --color=auto sendmail
sendmail的相关进程已经启动
ps aux | grep postfix
root 1161 0.0 0.0 112660 968 pts/1 R+ 11:04 0:00 grep --color=auto postfix
postfix的相关进程都没有开启
用PHP函数发送邮件
php -a
在PHP的交互界面下输入以下函数
mail('test@sohu.com', "Test email content", "sendmail title", null, "-f testname@sendmail.com");
* 使用PHP接口做测试的好处是可以随意指定发送方的邮件地址,即mail函数的最后一个参数。
即使系统的hostname未设置也可以正常发送出邮件。
六. 使用linux的mail命令发送邮件
mail命令就没有使用自定义的邮件发送地址,而是使用HOSTNAME。
安装系统时由于没有对hostname做特别设置,HOSTNAME的值是默认的 localhost.localdomain
这样的邮件域名会被大多数邮箱如163,QQ拒收。
查看邮件发送log会发现以下错误
cat /var/log/maillog
dsn=4.1.8, stat=Deferred: 450 4.1.8 <root@localhost.localdomain>: Sender address rejected: Domain not found
修改HOSTNAME
vi /etc/hosts
在最后加上一行
192.168.2.108 intest.com
这里的IP地址是我跑sendmail虚拟机的IP,需根据实际情况设置
* 其实这个文件hosts只是用来设置本地路由表,但填上本机IP时,系统在启动初始化中查到本机IP在hosts中,
就会用hosts文件中对应的域名来设置HOSTNAME。
重新启动
reboot -f
重启后发现本地的DNS配置文件etc/resolv.conf 已经被自动更新。
内容变成 nameserver 192.168.2.1
<
96a7
strong>执行mail命令发送邮件[/b]
echo "test mail content"|mail -s "Mail title" test@sohu.com
==========================================>
Postfix
<=========================================
一. 切换系统的邮件发送接口
alternatives --config mta
* Postfix是Centos7系统默认自带。 也可以用命令
yum list installed | grep postfix 确认
选择postfix所在行的编号后回车
二. 重启并测试功能
reboot -f
重启后查看进程看到postfix相关的进程已经启动
ps aux | grep postfix
root 1093 0.0 0.2 89544 2172 ? Ss 08:55 0:00 /usr/libexec/postfix/master -w
postfix 1094 0.0 0.4 89648 4016 ? S 08:55 0:00 pickup -l -t unix -u
postfix 1095 0.0 0.4 89716 4044 ? S 08:55 0:00 qmgr -l -t unix -u
postfix 1237 0.0 0.4 89796 4072 ? S 09:08 0:00 cleanup -z -t unix -u
postfix 1238 0.0 0.4 89652 4024 ? S 09:08 0:00 trivial-rewrite -n rewrite -t unix -u
postfix 1239 0.0 0.4 89856 4272 ? S 09:08 0:00 smtp -t unix -u
root 1274 0.0 0.0 112660 972 pts/1 R+ 09:09 0:00 grep --color=auto postfix
系统的hostname已经在sendmail配置的第六步中完成了配置,这里就直接使用PHP与mail命令
两种方法做测试。
php -a
mail('test@sohu.com', "Test email No1", "postfix mail", null, "-f test@ccfst.com");
* php的mail函数可以随意指定发送地址
echo "test mail"|mail -s "postfix mail title" test@sohu.com
==========================================>
相关文章推荐
- LNMP笔记:Centos下安装Postfix,替换sendmail发送邮件
- CentOS下通过postfix使用自己的gmail邮箱发送邮件
- 在 CentOS 7 中使用 Sendmail 通过 PHP 发送邮件
- CentOS6.5_64位系统下安装配置postfix邮件系统 启用并配置SMTP在第三方上边使用发送邮件
- CentOS 7 中使用 Sendmail 通过 PHP 发送邮件
- CentOS上使用sendmail发送邮件
- centos下如何使用sendmail发送邮件
- centos下如何使用sendmail发送邮件
- CentOS使用sendmail发送邮件
- Centos系统下VPS安装SendMail组件使WordPress支持发送邮件
- CentOS 7 中使用 Sendmail 通过 PHP 发送邮件
- CentOS 7 中使用 Sendmail 通过 PHP 发送邮件
- CentOS 7 中使用 Sendmail 通过 PHP 发送邮件
- Centos系统sendmail发送邮件很慢的解决方法
- CentOS如何用sendmail发送邮件
- CentOS 6.5 通过 PHP函数的sendmail 发送邮件
- CenTOS 5.6安装基于Postfix的邮件发送系统
- centos6.3下配置sendmail发送邮件
- CentOS 7 中使用 Sendmail 通过 PHP 发送邮件
- CentOS发送邮件(sendmail)