cPanel - 具有唯一的转发地址

cPanel - 具有唯一的转发地址

我正在尝试配置邮件[电子邮件保护]并对其进行配置,以便当[电子邮件保护]发送邮件至[电子邮件保护]它发给了 sarah@ jane@ 和 tom@ (抱歉,例子不太恰当!)

这封邮件必须发给所有“列表”与 FROM 来自[电子邮件保护]这样他们就可以在那里回复,其他人也都能收到。

主要的“批量电子邮件”提供商(phplist 等)似乎都无法通过这种方式进行配置。

我愿意接受建议,并希望我能解释清楚,如果没有,请要求澄清!

编辑:

我同意 Kyle Brants 的评论,这可以通过邮件列表(在 cPanel 中)MAILMAN 来完成,但我仍然不知道如何配置它!

谢谢!

答案1

您需要安装一个邮件列表程序,例如使用 cPanel 的 phpList。

前往 Fantastico De Luxe 并选择 phpList。

以下是 HostGator 的说明:http://support.hostgator.com/articles/e-mail/how-to-set-up-a-mailing-list-in-cpanel

答案2

SiteGround cPanel 电子邮件转发器教程应该解释设置转发器所需的一切。

10/20 编辑:编写一个 bash 脚本来完成这个任务看起来很有趣(至少一开始是这样),但是缺乏 MIME 多部分支持使得formail它很丑陋。

我可能会在以后尝试使用 PHP 脚本,但建议使用预先打包的解决方案比尝试自己动手更有意义。

10/21 编辑:我把这当作一种挑战,所以这里(不保证支持/工作代码)是我想到的 - 我仍然建议使用现有的解决方案超过使用这个脚本,但我无法抗拒编写概念验证脚本。

我使用 cPanel 安装使其工作,但我并不关心 MIME 支持,因此附件和 HTML 电子邮件将被删除,并且只会传递纯文本。

  1. 将脚本(如下)保存到文件中并更新以匹配您的 cPanel 配置
  2. 将文件上传到/home/example/mail-everyone.php(或类似)并按照管道到脚本设置指南(转发地址:“everyone”,管道到程序:“mail-everyone.php”)
  3. 发送一些测试消息 - 您应该会看到该消息NOTIFY_EMAIL通过调试电子邮件到达您的帐户(直到FLAG_DEBUG设​​置为 false),并且所有其他启用 cPanel 的电子邮件地址都应该看到纯文本 BCC 副本。

--

<?php
define( 'FLAG_DEBUG', true ); // default: true
define( 'FLAG_DEBUG_RAW', false ); // default: false
define( 'NOTIFY_EMAIL', '[email protected]' );
define( 'CPANEL_DOMAIN', 'example.com' );
define( 'CPANEL_PATH', '/home/example/' );
define( 'CPANEL_PATH_USERS', constant('CPANEL_PATH') . 'etc/' . constant('CPANEL_DOMAIN') . '/quota' );
define( 'EML_SENDER', 'everyone@' . constant('CPANEL_DOMAIN') );
define( 'EML_SUBJECT_PREPEND', '(everyone) ' );
define( 'EML_SUBJECT_APPEND', '' );
define( 'EML_XMAILER', __FILE__.'; PHP/'.phpversion() );
define( 'END_LINE', "\r\n" );

function debugging( $message, $notify = false ) {
    global $debugging;
    if ( defined('FLAG_DEBUG') && constant('FLAG_DEBUG') ) {
        $debugging[] = $message;
    }
    if ( $notify ) {
        $outgoing_headers = array(
            'From' => constant('EML_SENDER'),
            'Reply-To' => constant('NOTIFY_EMAIL'),
            'X-Mailer' => constant('EML_XMAILER')
        );
        $message = implode( constant('END_LINE'), $debugging );
        $flag_sent = send_mail( constant('NOTIFY_EMAIL'), __FILE__.': Debug Notice', $message, $outgoing_headers );
    }
    return;
}
function scan_headers( $search, $target ) {
    $matches = array();
    $pattern = '/^' . strtolower($target) . ':/i';
    if ( preg_match( $pattern, $search ) ) {
        return substr( $search, strlen($target . ': ') );
    }
}
function send_mail( $to, $subject, $message, $headers_array = false ) {
    if ( is_array($headers_array) ) {
        $header_string = '';
        foreach ( $headers_array as $key => $value ) {
            $header_string .= $key.': '.$value . constant('END_LINE');
        }
    }
    return ( @mail( $to, $subject, $message, $header_string ) );
}
if (
    !defined('CPANEL_DOMAIN') ||
    !defined('CPANEL_PATH') ||
    !defined('CPANEL_PATH_USERS') ||
    !defined('EML_SENDER') ||
    !defined('EML_XMAILER') ||
    !defined('FLAG_DEBUG') ||
    !defined('FLAG_DEBUG_RAW') ||
    !defined('NOTIFY_EMAIL') ||
    !defined('END_LINE') ||
    constant('NOTIFY_EMAIL') == constant('EML_SENDER')
) {
    exit(1);
}
$debugging = array();
$flag_headers = 1;
$flag_plaintext = 1;
$flag_multi_plaintext = 0;
$flag_multi_plaintext_done = 0;
$headers_incoming = array(
    'To' => '',
    'From' => '',
    'Reply-To' => '',
    'Subject' => '',
    'Cc' => ''
);
$mime_boundary = '';
$plaintext = '';
debugging('searching for users');
$users = array();
$quota_users = @file( constant('CPANEL_PATH_USERS') );
if ( $quota_users && is_array($quota_users) && count($quota_users) ) {
    foreach ( $quota_users as $quota_user ) {
        $user = strtok($quota_user,':') . '@' . constant('CPANEL_DOMAIN');
        debugging('searching for users: +user "'.$user.'"');
        $users[] = $user;
    }
} else {
    debugging('searching for users: ERROR - check CPANEL_PATH_USERS "'.constant('CPANEL_PATH_USERS').'"', true);
    exit(1);
}
debugging('searching for users done: ' . count($users) . ' users');
debugging('header processing begins');
$line_count = 0;
$line_last = '';
while( $line = fgets(STDIN) ) {
    if ( $line_count >= 5000 ) break;
    $line = trim($line);
    if ( $flag_headers ) {
        foreach ( $headers_incoming as $target => $set ) {
            if ( !$set ) {
                $found = scan_headers( $line, $target );
                if ( $found ) {
                    $headers_incoming[$target] = $found;
                    debugging('headers: set '.$target.': "'.$found.'"');
                }
            }
        }
        if ( strpos($line, 'boundary=') ) {
            $flag_plaintext = false;
            debugging('headers: multipart message detected');
        }
        if ( strlen($line) <= 3 ) {
            $flag_headers = false;
            debugging('header processing ends');
        }
    } else if ( $flag_plaintext ) {
        // (default) plain text message
        //           everything after headers will be relayed
        debugging('plaintext: +line "'.$line.'"');
        $plaintext .= $line . constant('END_LINE');
    } else if ( $flag_multi_plaintext ) {
        if ( preg_match( '/^' . $mime_boundary . '/', $line ) ) {
            debugging('multipart/text: reached boundary "'.$mime_boundary.'"');
            $flag_multi_plaintext = false;
            $flag_multi_plaintext_done = true;
        } else {
            debugging('multipart/text: +line "'.$line.'"');
            $plaintext .= $line . constant('END_LINE');
        }
    } else if ( !$flag_multi_plaintext_done ) {
        if ( preg_match( '/^Content-Type: text\/plain/', $line ) ) {
            $mime_boundary = $line_last;
            debugging('multipart/text: matched "Content-Type: text/plain" header');
            $flag_multi_plaintext = true;
        }
    }
    if ( constant('FLAG_DEBUG_RAW') ) debugging( 'raw message: +line "' . $line . '"' );
    $line_last = $line;
    $line_count++;
}
if (
    $headers_incoming['To'] != constant('EML_SENDER') ||
    $headers_incoming['From'] == constant('EML_SENDER')
) {
    debugging( 'skipped resending to avoid loop - To: "'.$headers_incoming['To'].'" / From: "'.$headers_incoming['From'].'"', constant('FLAG_DEBUG') );
    exit(0);
}
debugging('resending begins');
if ( strlen($plaintext) ) {
    $reply_recipient = ($headers_incoming['Reply-To']) ? $headers_incoming['Reply-To'] : $headers_incoming['From'];

    $subject = $headers_incoming['Subject'];
    $subject = (defined('EML_SUBJECT_PREPEND')) ? constant('EML_SUBJECT_PREPEND') . $subject : $subject;
    $subject = (defined('EML_SUBJECT_APPEND')) ? $subject . constant('EML_SUBJECT_APPEND') : $subject;
    $users_bcc = '';
    foreach ( $users as $user_email ) {
        debugging('resending: +email bcc: "'.$user_email.'"');
        $users_bcc .= ($users_bcc) ? ',' . $user_email : $user_email;
    }
    $outgoing_headers = array(
        'From' => constant('EML_SENDER'),
        'Cc' => constant('EML_SENDER'),
        'Bcc' => $users_bcc,
        'Reply-To' => $reply_recipient,
        'X-Mailer' => constant('EML_XMAILER')
    );
    if ( send_mail( constant('NOTIFY_EMAIL'), $subject, $plaintext, $outgoing_headers ) ) {
        debugging( 'resending ends - success', constant('FLAG_DEBUG') );
    } else {
        debugging('resending: failed sending to "'.$users_bcc.'"', constant('FLAG_DEBUG') );
        exit(1);
    }
} else {
    debugging( 'error: nothing to relay', true );
    exit(1);
}
exit(0);
?>

相关内容