Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

multiple CC using sendmail

by Hammy (Scribe)
on Jun 25, 2007 at 23:52 UTC ( #623284=perlquestion: print w/replies, xml ) Need Help??
Hammy has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I am using sendmail to push some dynamic emails to my users. I need to either CC or BCC multiple users. When I have one CC or one BCC it works well, but if I add an additional name separated by ';' I get a system error. If I separate by ',' it just does not work. The users are registering and I need to let many people know about the registration. The code I am using is below:
$lines[0] = "To: $email\n"; $lines[1] = "From: $from\n"; $lines[2] = "Bcc: support\@mysite.com\n"; $lines[3] = "MIME-Version: 1.0\n"; $lines[4] = "Content-Type: text/html; charset=us-ascii\n"; $lines[5] = "Subject: $subject\n\n"; $lines[6] = "$theMessage"; open(MAIL,"|/usr/sbin/sendmail -t") or fatal("..."); print MAIL @lines; close(MAIL) or fatal("...");
Is there something I am missing? Thanks for your help.

Replies are listed 'Best First'.
Re: multiple CC using sendmail
by Joost (Canon) on Jun 26, 2007 at 00:12 UTC
    First of all, IIRC, sendmail does not support separating adresses with ";", you need to use ",".

    Also "It just does not work" is not a good description of what's going wrong, so I can't really help you there. See also How do I post a question effectively?. Especially helpful would be: what does open(MAIL,"|/usr/sbin/sendmail -t") or fatal("..."); print to stderr?

    See also http://perldoc.perl.org/perlfaq9.html#How-do-I-send-mail%3f which describes how to send mail from perl using sendmail.

    Also also: there's no need to use the cumbersome array assignment to create the message. You can use "here docs" instead, for example:

    my $msg = <<"ENDMSG"; To: $email From: $from Bcc: support\@mysite.com MIME-Version: 1.0 Content-Type: text/html; charset=us-ascii Subject: $subject $theMessage ENDMSG # continue here and print $msg to sendmail
      Thanks for your quick response. I appologize for not being specific about sending the emails. What I meant by does not work is:

      When separating by ',' - no emails are sent.

      Now I must clarify. I made your suggestion to use comma in the Bcc and it sent the email to everyone I asked it to. Great. So I went back to my original need which is multiple people in the To: field and it does not send an email to anyone in the To: field. So I had two people in the To: field and two people in the Bcc: field. Both Bcc: people arrived, neither To: field arrived.

      Thanks again.
Re: multiple CC using sendmail
by sago (Scribe) on Jun 26, 2007 at 09:29 UTC


    Try this code.

    #!C:/Perl/bin/perl.exe
    use MIME::Lite;
    MIME::Lite->send('smtp', "mailtesthub.gmail.com", Timeout=>90);
    my $email = "This email was generated automatically.";
    my $subject = "hello test";
    my $MailFrom = "john@gmail.com";
    my $to_list = 'frank@yahoo.com,kannan@gmail.com,stepen@gmail.com';
    my $cc_list = 'sam@rediffmail.com,goerge@gmail.com,jansi@yahoo.com';
    my $bcc_list = 'yami@yahoo.com,bala@yahoo.com';
    $msg = MIME::Lite->new(
    From => $MailFrom,
    To => $to_list,
    Cc => $cc_list,
    Bcc => $bcc_list,
    Subject => $subject,
    Type => 'TEXT',
    Encoding=> '7bit',
    Data => $a
    );
    $msg->send()
      Use the option -t to send it to multiple addresses in the "To" field.
Re: multiple CC using sendmail
by Anonymous Monk on Jun 26, 2007 at 05:03 UTC
    man sendmail

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://623284]
Approved by Joost
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2018-07-23 04:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (459 votes). Check out past polls.

    Notices?