Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to configure a mail everyone@example.com and configure it so that when, lets say, john@example.com sends a mail to everyone@example.com it gets to sarah@ jane@ and tom@ (sorry for the lame examples!)

This mail has to get to all the "list" with the FROM from everyone@example.com so that they can just reply there and everybody else will get it.

None of the main "bulk email" providers (phplist etc) seems to be configurable that way.

I´m open to suggestions and I hope I´m explaining myself, if not please ask for clarifications!

EDIT:

I agree with Kyle Brants´ comment this could be done with mailing list (in cPanel) MAILMAN but I still have no idea how to configure it!

Thanks!

share|improve this question
    
I am not familiar with cpanel in particular, but what you are looking for is generally referred to as a "Mailing list". –  Kyle Brandt Oct 19 '10 at 22:36
    
Okay, so sender@example.com sends a message to everyone@yourdomain.com and you want the message to be sent to a list of e-mails @yourdomain.com with a reply-to address of the sender and a CC address of everyone@yourdomain.com right? –  danlefree Oct 20 '10 at 5:15

2 Answers 2

You need to install a mailing list program, like phpList using cPanel.

Go to Fantastico De Luxe and choose phpList.

Here are HostGator's instructions: http://support.hostgator.com/articles/e-mail/how-to-set-up-a-mailing-list-in-cpanel .

share|improve this answer
    
Hi, I wrote in my question "None of the main "bulk email" providers (phplist etc) seems to be configurable that way." Maybe I don´t know how to configure them but that is what I need! Thanks you very much –  Trufa Oct 19 '10 at 23:12
    
Ok, here's some info about how to install mailman on cpanel wiki.list.org/display/DOC/Mailman+and+CPanel. Specifically they suggest this joomla extension extensions.joomla.org/extensions/2409/details . I think the joomla extension might be an easy way to go. –  SLY Oct 20 '10 at 2:42

This SiteGround cPanel E-mail Forwarder Tutorial should explain everything you need to get a forwarder set up.

10/20 Edit: Writing a bash script to accomplish this task seemed like it would be fun (at first, anyway) but the lack of MIME multipart support in formail makes it ugly.

I might give a PHP script a try at a later date, but the suggestion to use a prepackaged solution makes more sense than trying to roll one's own.

10/21 Edit: I took this one as a kind of challenge so here (without any guarantee of support/working code) is what I came up with - I still recommend using an existing solution over using this script, but I couldn't resist scripting a proof-of-concept.

I got it working with a cPanel installation but I haven't bothered w/MIME support so attachments and HTML e-mail will be stripped and only plaintext will get delivered.

  1. Save the script (below) to a file and update to match your cPanel configuration
  2. Upload the file to /home/example/mail-everyone.php (or similar) and follow the pipe-to-script setup guide (Address to Forward: "everyone", Pipe to program: "mail-everyone.php")
  3. Send a few test messages - you should see the message hit your NOTIFY_EMAIL account with a debugging e-mail (until FLAG_DEBUG is set to false) and all other cPanel-enabled e-mail addresses should see plaintext BCC copies.

--

<?php
define( 'FLAG_DEBUG', true ); // default: true
define( 'FLAG_DEBUG_RAW', false ); // default: false
define( 'NOTIFY_EMAIL', 'you@example.com' );
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);
?>
share|improve this answer
    
Thank you you are heading the right direction but this is the problem I am trying to solve, I have this set so when sender@example.com sends me and email, the from is sender@example.com with CC to everyone@example.com, I want it to be only from everyone@example.com and I want to be able to modify the title to (everyone) + the original title. Is this clear?? thank you very much! –  Trufa Oct 20 '10 at 4:55
    
@Trufa - OK - and I'm seeing that now cPanel won't allow multiple addresses for forwarding... let me see what I can script up :) –  danlefree Oct 20 '10 at 4:57
    
Thank you very much, I wouldnt know really where to start. I editing the title before forwarding any easier? I mean add (everyone) at the beginning of the title? I appreciate the effort! –  Trufa Oct 20 '10 at 14:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.