【发布时间】:2014-05-23 15:34:01
【问题描述】:
有人告诉我在 stackoverflow 中重新发布此内容,因为它实际上可能不是后缀问题。但是,我对 php postfix 交互性知之甚少,所以如果脚本部分有问题并且有人可以看到,请告诉我。我不确定是否有一种特殊的方法可以让邮件正常传递(进出),一旦它通过脚本,如果这甚至是问题。谢谢!
--
在我工作的时候,我制作了一份我正在做的事情的指南,以备将来使用。我一直试图让它工作一段时间,并且我已经让电子邮件通过脚本。问题是所有收到的邮件,被退回或以其他方式,在收到邮件并且脚本完成运行后没有被放入邮箱。该脚本确实运行并在内部执行所有操作,并且没有错误地退出,我可以补充一下。
添加目录: $sudo mkdir /usr/local/bouncehandler
将脚本文件添加到 /usr/local/bouncehandler: mybh.php
允许执行脚本: chmod a+x mybh.php
添加用户: $sudo useradd 弹跳
(创建 /etc/postfix/virtual_aliases 以添加包罗万象的别名 -- localuser 需要是现有的本地用户: bounces@bounces.mydomain.com root:) 整个步骤都被删除了
创建 /etc/postfix/transport 以添加传输映射。 “mytransportname”可以是任何你想要的;它在 master.cf 中使用如下: mydomain.com mybh:
接下来,transport 和 virtual_aliases 都需要编译成 db 文件: ($sudo postmap /etc/postfix/virtual_aliases)删除 $sudo postmap /etc/postfix/transport
/etc/postfix/master.cf 中的更改: smtp inet n - - - - smtpd (-o content_filter=mybh:dummy)已移除
将传输添加到 /etc/postfix/master.cf: mybh unix - n n - 10 管道 flags=q user=bounce argv=/usr/local/bouncehandler/mybh.php ${sender} ${recipient}
-
/etc/postfix/master.cf 中的更改:
拾取fifo n - - 60 1 拾取 (-o content_filter=mybh:dummy)已移除
在 /etc/postfix/main.cf:
transport_maps = hash:/etc/postfix/transport (virtual_alias_maps = hash:/etc/postfix/virtual_aliases))已移除
-
连接数据库并创建表bounce_list:
如果不存在则创建表bounce_list ( 电子邮件 VARCHAR(255) NOT NULL PRIMARY KEY, 反弹计数 INT(4) 非空 )ENGINE=InnoDB;
重启后缀:
$sudo 后缀重载
我通过的脚本检查收件人是否是我的域,我相信这表明它是发送给我的。如果是,我检查它最初是否发送给其他人,如果是,我检查用户并将电子邮件视为已退回。我没有在脚本中做任何其他事情,所以我不确定在那之后我是否应该调用原始邮件脚本(如果有的话)。
mybh.php:
#!/usr/bin/php -q
<?php
////////////////////////////////////////////////////////
//Collects sender and recipient data from email pass
////////////////////////////////////////////////////////
$sender = trim($argv[1]);
$recipient = trim($argv[2]);
$bounceProcd = FALSE;
list($name, $domain) = explode('@', $recipient);
if(strpos($recipient, 'mydomain.com') !== false)
{
////////////////////////////////////////////////////////
//Database variable initialization
////////////////////////////////////////////////////////
$host = "localhost";
$user = "user";
$pass = "password";
$db = "database";
////////////////////////////////////////////////////////
//Establish database connection
////////////////////////////////////////////////////////
$con = mysqli_connect($host, $user, $pass, $db);
////////////////////////////////////////////////////////
//Verify that database is connected properly
////////////////////////////////////////////////////////
if(!$con)
{
exit(75);
}
////////////////////////////////////////////////////////
//Initialize query into variable
////////////////////////////////////////////////////////
$query = "INSERT INTO bounce_list VALUES ('$recipient', 1) ON DUPLICATE KEY UPDATE bounce_count = bounce_count + 1";
////////////////////////////////////////////////////////
//Run query and store in variable
////////////////////////////////////////////////////////
$result = mysqli_query($con, $query);
$bounceProcd = mysqli_affected_rows($con) > 0;
////////////////////////////////////////////////////////
//Verify that query executed
////////////////////////////////////////////////////////
if (!$result) {
$con->close();
exit(75);
}
$con->close();
$dataLen = IgnoreMessageData();
}
$exitStatus = (TRUE == $bounceProcd) ? 0 : 75;
////////////////////////////////////////////////////////
//Pass email to mailbox
////////////////////////////////////////////////////////
exit($exitStatus+0);
function IgnoreMessageData()
{
$msgLen = 0;
$fd = fopen('php://stdin', 'r');
while (FALSE === feof($fd))
{
$dunsel = fread($fd, 1024);
$msgLen += strlen($dunsel);
}
fclose($fd);
return $msgLen;
}
return;
?>
main.cf:
# See /usr/share/postfix/main.cf.dist for a commented, more complete
version
# Debian specific: Specifying a file name will cause the first
# line of that file to be used as the name. The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no
# appending .domain is the MUA's job.
append_dot_mydomain = no
# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h
readme_directory = no
# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/sslcertsnakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/sslcertsnakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
# See /usr/share/doc/postfix/TLS_README.gz in the postfixdoc package for
# information on enabling SSL in the smtp client.
myhostname = main.mydomain.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
smtp_generic_maps = hash:/etc/postfix/generic
myorigin = /etc/mailname
mydestination = admin.mydomain.com, main.mydomain.com,
localhost.mydomain.com, localhost
relayhost =
mynetworks = (deleted this line)
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
transport_maps = hash:/etc/postfix/transport
master.cf:
#
# Postfix master process configuration file. For details on the format
# of the file, see the master(5) manual page (command: "man 5 master").
#
# Do not forget to execute "postfix reload" after editing this file.
#
# ==========================================================================
# service type private unpriv chroot wakeup maxproc command + args
# (yes) (yes) (yes) (never) (100)
# ==========================================================================
smtp inet n - - - - smtpd
mybh unix - n n - - pipe
flags=q user=bounce argv=/usr/local/bouncehandler/mybh.php ${sender} ${recipient}
#smtp inet n - - - 1 postscreen
#smtpd pass - - - - - smtpd
#dnsblog unix - - - - 0 dnsblog
#tlsproxy unix - - - - 0 tlsproxy
#submission inet n - - - - smtpd
# -o syslog_name=postfix/submission
# -o smtpd_tls_security_level=encrypt
# -o smtpd_sasl_auth_enable=yes
# -o smtpd_client_restrictions=permit_sasl_authenticated,reject
# -o milter_macro_daemon_name=ORIGINATING
#smtps inet n - - - - smtpd
# -o syslog_name=postfix/smtps
# -o smtpd_tls_wrappermode=yes
# -o smtpd_sasl_auth_enable=yes
# -o smtpd_client_restrictions=permit_sasl_authenticated,reject
# -o milter_macro_daemon_name=ORIGINATING
#628 inet n - - - - qmqpd
pickup fifo n - - 60 1 pickup
cleanup unix n - - - 0 cleanup
qmgr fifo n - n 300 1 qmgr
#qmgr fifo n - n 300 1 oqmgr
tlsmgr unix - - - 1000? 1 tlsmgr
rewrite unix - - - - - trivial-rewrite
bounce unix - - - - 0 bounce
defer unix - - - - 0 bounce
trace unix - - - - 0 bounce
verify unix - - - - 1 verify
flush unix n - - 1000? 0 flush
proxymap unix - - n - - proxymap
proxywrite unix - - n - 1 proxymap
smtp unix - - - - - smtp
relay unix - - - - - smtp
# -o smtp_helo_timeout=5 -o smtp_connect_timeout=5
showq unix n - - - - showq
error unix - - - - - error
retry unix - - - - - error
discard unix - - - - - discard
local unix - n n - - local
virtual unix - n n - - virtual
lmtp unix - - - - - lmtp
anvil unix - - - - 1 anvil
scache unix - - - - 1 scache
#
# ====================================================================
# Interfaces to non-Postfix software. Be sure to examine the manual
# pages of the non-Postfix software to find out what options it wants.
#
# Many of the following services use the Postfix pipe(8) delivery
# agent. See the pipe(8) man page for information about ${recipient}
# and other message envelope options.
# ====================================================================
#
# maildrop. See the Postfix MAILDROP_README file for details.
# Also specify in main.cf: maildrop_destination_recipient_limit=1
#
maildrop unix - n n - - pipe
flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}
#
# ====================================================================
#
# Recent Cyrus versions can use the existing "lmtp" master.cf entry.
#
# Specify in cyrus.conf:
# lmtp cmd="lmtpd -a" listen="localhost:lmtp" proto=tcp4
#
# Specify in main.cf one or more of the following:
# mailbox_transport = lmtp:inet:localhost
# virtual_transport = lmtp:inet:localhost
#
# ====================================================================
#
# Cyrus 2.1.5 (Amos Gouaux)
# Also specify in main.cf: cyrus_destination_recipient_limit=1
#
#cyrus unix - n n - - pipe
# user=cyrus argv=/cyrus/bin/deliver -e -r ${sender} -m ${extension} ${user}
#
# ====================================================================
# Old example of delivery via Cyrus.
#
#old-cyrus unix - n n - - pipe
# flags=R user=cyrus argv=/cyrus/bin/deliver -e -m ${extension} ${user}
#
# ====================================================================
#
# See the Postfix UUCP_README file for configuration details.
#
uucp unix - n n - - pipe
flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient)
#
# Other external delivery methods.
#
ifmail unix - n n - - pipe
flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient)
bsmtp unix - n n - - pipe
flags=Fq. user=bsmtp argv=/usr/lib/bsmtp/bsmtp -t$nexthop -f$sender $recipient
scalemail-backend unix - n n - 2 pipe
flags=R user=scalemail argv=/usr/lib/scalemail/bin/scalemail-store ${nexthop} ${user} ${extension}
mailman unix - n n - - pipe
flags=FR user=list argv=/usr/lib/mailman/bin/postfix-to-mailman.py
${nexthop} ${user}
邮件日志:
4 月 16 日 05:55:37 服务器名称后缀/拾取 [1774]: 48F1F2C0663: uid=0 来自=
4 月 16 日 05:55:37 服务器名称后缀/清理[1789]:48F1F2C0663: message-id=
Apr 16 05:55:37 serverName postfix/qmgr[1773]: 48F1F2C0663: from=, size=294, nrcpt=1(队列活动)
Apr 16 05:55:58 serverName postfix/smtp[1791]: 48F1F2C0663: to=, 中继=mail.digitalsanctuary.com[174.73.49.123]:52,延迟=40, 延迟=19/0.01/0.42/20,dsn=5.1.1,状态=反弹(主机 mail.digitalssanctuary.com[174.37.94.132] 说:550 5.1.1 :收件人地址 拒绝:虚拟别名表中的用户未知(回复 RCPT TO 命令))
4 月 16 日 05:55:58 服务器名称后缀/清理[1789]:3F13A2C0869: message-id=
Apr 16 05:55:58 serverName postfix/bounce[1800]: 48F1F2C0663: sender 未送达通知:3F13A2C0869
Apr 16 05:55:58 serverName postfix/qmgr[1773]: 3F13A2C0869: from=, size=2513,nrcpt=1(队列活动)
4 月 16 日 05:55:58 serverName postfix/qmgr[1773]: 48F1F2C0663: 已移除
4 月 16 日 05:55:58 服务器名称后缀/管道[1801]:3F13A2C0869: to=, 中继=mybh, 延迟=0.04, delays=0/0/0/0.03, dsn=2.0.0, status=sent(通过 mybh 服务交付)
4 月 16 日 05:55:58 serverName postfix/qmgr[1773]: 3F13A2C0869: 已移除
我已经包含了所有我认为可能有用的信息,这些信息来自我在阅读许多指南和许多其他帖子时看到的必要信息,并试图自己弄清楚这一点。
如果有一双新的眼睛可以帮助我,我将不胜感激。
- 我还想知道,如果有人知道如何执行此操作,请将原始目标电子邮件附加到退回的电子邮件中。
谢谢
【问题讨论】:
标签: php email postfix-mta email-bounces