MENU

BT面板使用Postfix纯接收邮件的服务

March 4, 2024 • 已被 784 位童鞋围观过 • 教程文章

安装宝塔邮局后,关闭其他无效服务。

修改postfix配置文件

readme_directory = /usr/share/doc/postfix3-3.4.7/README_FILES
meta_directory = /etc/postfix
shlib_directory = /usr/lib/postfix
myhostname = {yourdomain.com}
virtual_mailbox_domains = sqlite:/etc/postfix/sqlite_virtual_domains_maps.cf
#virtual_alias_maps = sqlite:/etc/postfix/sqlite_virtual_alias_maps.cf, sqlite:/etc/postfix/sqlite_virtual_alias_domain_maps.cf, sqlite:/etc/postfix/sqlite_virtual_alias_domain_catchall_maps.cf
#virtual_mailbox_maps = sqlite:/etc/postfix/sqlite_virtual_mailbox_maps.cf, sqlite:/etc/postfix/sqlite_virtual_alias_domain_mailbox_maps.cf
#smtpd_sasl_type = dovecot
#smtpd_sasl_path = private/auth
#smtpd_sasl_auth_enable = yes
#smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination
#smtpd_use_tls = yes
#smtp_tls_security_level = none
#smtpd_tls_security_level = none
#default_transport = toRedis
virtual_transport = toRedis
#smtpd_milters = inet:127.0.0.1:11332
#non_smtpd_milters = inet:127.0.0.1:11332
#milter_mail_macros = i {mail_addr} {client_addr} {client_name} {auth_authen}
#milter_protocol = 6
#milter_default_action = accept
message_size_limit = 102400000

修改 /etc/postfix/master.cf 文件添加管道toRedis

toRedis    unix  -       n       n       -       -       pipe
  flags=FR user=nobody argv=/www/server/php/80/bin/php /home/postfix/toRedis.php ${recipient}

重启服务即可

toRedis.php的代码

<?php
// Redis 连接设置
$redisHost = '127.0.0.1';
$redisPort = 6379;
$queueName = 'postfixQueue';
// 创建 Redis 实例并连接
$redis = new Redis();
$connected = $redis->connect($redisHost, $redisPort);

$redis->select(0);
// 从标准输入读取邮件内容
$emailContent = stream_get_contents(STDIN);
// 将邮件内容添加到 Redis 队列
$redis->lPush($queueName, $emailContent);