2023-05-12 开启多语言插件支持……

64位 centos 6.4 linux系统配置 postfix 启用 smtp 认证

Linux 苏 demo 2235℃ 0评论

配置 Postfix 启用 SMTP 认证
1. 安装 cyrus-sasl 软件包,它牵涉的依赖关系包比较多,命令如下:
yum -y install cyrus-sasl*
命令的结果显示,如下:
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
* epel: ftp.kddilabs.jp
Setting up Install Process
Package cyrus-sasl-lib-2.1.23-13.el6_3.1.x86_64 already installed and latest version
Package cyrus-sasl-ntlm-2.1.23-13.el6_3.1.x86_64 already installed and latest version
Package cyrus-sasl-plain-2.1.23-13.el6_3.1.x86_64 already installed and latest version
Package cyrus-sasl-md5-2.1.23-13.el6_3.1.x86_64 already installed and latest version
Package cyrus-sasl-2.1.23-13.el6_3.1.x86_64 already installed and latest version
Package cyrus-sasl-devel-2.1.23-13.el6_3.1.x86_64 already installed and latest version
Package cyrus-sasl-ldap-2.1.23-13.el6_3.1.x86_64 already installed and latest version
Package cyrus-sasl-sql-2.1.23-13.el6_3.1.x86_64 already installed and latest version
Package cyrus-sasl-gssapi-2.1.23-13.el6_3.1.x86_64 already installed and latest version
Nothing to do
因为我已经安装过了,所以显示的是 Nothing to do,你第一次安装,会有几个 Complete。
我们可以用以下命令启动 saslauthd 服务,并配置成自启动服务:
service saslauthd start
chkconfig saslauthd on
2. 添加下列内容到主配置文件,让 Postfix 启用 SMTP 认证,
# 把此代码添加到 /etc/postfix/main.cf 最后
# smtp
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = ”
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
broken_sasl_auth_clients = yes
smtpd_client_restrictions = permit_sasl_authenticated
smtpd_sasl_security_options = noanonymous
完成以上步骤后,全新加载配置,命令如下:
postfix reload
测试
使用 phpmailer 测试 Postfix 的 SMTP 是否有效,
phpmailer 请自行下载,下载地址: github.com/Synchro/PHPMailer
PHP 测试代码:
test.php
<?php
set_time_limit (0);
require_once(‘./class.phpmailer.php’);
// 测试发送附件专用
$tmp_file = ‘/tmp/test.jpg’;
$mail = new PHPMailer(true);
// 是否为 SMTP 认证
$mail->IsSMTP();
try {
// 服务器 IP,程序在本地使用,所以填写 127.0.0.1,
$mail->Host       = “127.0.0.1”;
// 调试模式关闭
$mail->SMTPDebug  = 0;
// 是否开户 SMTP 认证
$mail->SMTPAuth   = true;
// SMTP 认证用户名,此处填写系统用户名,可以专门创建一个普通用户用于发送邮件
$mail->Username   = “username”;
// SMTP 认证用户密码,此处填写与系统用户名对应的系统用户密码
$mail->Password   = ‘password’;
// 设置邮件内容字符集,防止中文乱码
$mail->CharSet = ‘UTF-8’;
// 接收邮件地址
$mail->AddAddress(‘abcdef@126.com’, ‘忙碌的松鼠’);
// 设置我的邮件地址
$mail->SetFrom(‘info@example.com’, ‘忙碌的松鼠’);
// 邮件标题
$mail->Subject = ‘欢迎大家关注 忙碌的松鼠’;
// 邮件内容,可以是HTML代码
$mail->MsgHTML(‘欢迎大家关注 忙碌的松鼠 博客,博客地址:http;//www.gretheer.com’);
// 添加附件
$mail->AddAttachment($tmp_file);
// 发送
$mail->Send();
} catch (Exception $e) {
// 报错信息
echo $mail->ErrorInfo;
}
?>

注意:
1. 可以在命令行下测试,最好使用普通用户测试。
php test.php
2. 用浏览器访问PHP文件测试时,如果没有接收到邮件,看是否是PHP文件权限问题,包括PHP文件内,include,require 等包含的文件的权限。

打赏

转载请注明:苏demo的别样人生 » 64位 centos 6.4 linux系统配置 postfix 启用 smtp 认证

   如果本篇文章对您有帮助,欢迎向博主进行赞助,赞助时请写上您的用户名。
支付宝直接捐助帐号oracle_lee@qq.com 感谢支持!
喜欢 (0)or分享 (0)