后缀/Dovecot
例如,我想为后缀创建我的simple自定义自动响应器。我不需要任何第三方现成的。
我希望它有一些自定义条件,例如“只有当‘从== A’或/和‘到== B’或/和”今天还没有自动回复该电子邮件‘时才自动回复,等等。
我发现我需要使用content_filter或在master.cf中生成。不是milter,因为milter是因为消息被放入队列而触发的,而我需要自动回复已经通过的消息。可能吧。
其他更好的选择?
如何做到这一点?
发布于 2019-10-21 05:44:16
我不认为有一种简单的(即琐碎的)方法来做到这一点,而且很可能有多种解决方案。
我为我的邮件系统(它承载了相当数量的框和域)和自定义的书面CMS (BLISS3)实现了这一点,如下所示:
添加到/etc/后缀/master.cf. to
autoresponder
unix - n n - - pipe flags=Rq
user=mailuser argv=/etc/postfix/scripts/autoresponder.php ${sender} ${recipient}这将执行我的脚本autoresponder.php,解析发送方和收件人。如果您愿意,可以在python中编写适当的自动响应程序。
然后,我在/etc/后缀/传输中添加了以下内容
.autoresponder autoresponder:当我将电子邮件的副本发送到特殊的"user@domain.name.autoresponder“电子邮件时,此命令触发自动响应器作为适当的传输。如果你想在小范围内这样做,你可以简单地用你的电子邮件地址代替".autoresponder“,如果你不需要保留收到的电子邮件的副本。
剩下的就是自动响应程序脚本本身。
我的PHP脚本如下所示:
#! /usr/bin/php
GetAll("select count(uid) from autoresponded where mailfrom='$from' and mailto='$to' and date > current_timestamp - interval '$period'");
if ( $sent[0]['count'] < 1 and $from != $to )
{
$q=$conn->Execute("insert into autoresponded (date,mailfrom,mailto) values (current_timestamp,'$from','$to')");
$messages=$conn->GetAll("select ar_subject, ar_body from virtual where mailfrom='".$from."'");
# No point in sending if we don't have a message to send.
if ($messages[0]['ar_subject'] != '' or $messages[0]['ar_body'] != '')
{
$headers='From: '.$from."\r\n";
$subject=pg_unescape_bytea($messages[0]['ar_subject']);
$message=pg_unescape_bytea($messages[0]['ar_body']);
mail ($to, $subject, $message,$headers);
}
}
# Automatically clean up after ourself.
$cleanup=$conn->Execute("delete from autoresponded where date < current_timestamp - interval '$period'");如您所见,我使用一个简单的数据库来跟踪电子邮件最后一次发送到给定地址的时间,我检查该地址,以确保每个发件人每天发送的回复不超过一个,以防止邮件循环和其他麻烦。实际的回复者电子邮件是通过一个简单的邮件命令(第6行)完成的。
如果您想做类似的事情,那么我的自动响应表的架构是:
Table "public.autoresponded"
Column | Type | Collation | Nullable | Default
----------+-----------------------------+-----------+----------+--------------------------------------------
uid | integer | | not null | nextval('autoresponded_uid_seq'::regclass)
date | timestamp without time zone | | | now()
mailfrom | character varying | | |
mailto | character varying | | | 引用ar_header和ar_body的行从数据库中提取适当的自动响应头和正文。您可以创建/修改自己的表来执行此操作或对其进行硬编码。
希望上面给你一个坚实的起点来做你想做的事情。按照下面的@TobiM注释,使用它作为代码的基础--您可能应该用准备好的状态替换sql。实际上,我还没有检查修改后的版本是否有效,它假设是mysql数据库。
https://serverfault.com/questions/988717
复制相似问题