Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Email::MIME won't send email to Bcc addresses

by fshrewsb (Acolyte)
on Jan 11, 2012 at 09:20 UTC ( #947314=perlquestion: print w/replies, xml ) Need Help??

fshrewsb has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm using Email::Mime to construct an object like this :

my $email = Email::MIME->create( header_str =>[ To => $email_to, Cc => $email_cc, Bcc => $email_bcc, From => $email_from, Subject => $email_subject ], body_str =>$email_body, attributes => { content_type => 'text/html', charset => 'utf8', encoding => 'quoted-printable' } );

and sending it using this :

try { sendmail( $email, { from => $email_from, transport => Email::Sender::Transport::SMTP->new({host => $S +MTP_HOSTNAME,port => $SMTP_PORT}) } ); } catch { print $_->message};

If I do a print $email->as_string I can see the Bcc header, but when I do a tcpdump I can see that there is no RCPT TO: message for the Bcc email address. To and Cc email addresses receive the email. Does anyone know how to get Email:MIME to work with Bcc ? Email:Stuff works, but I would prefer to use Email:MIME.

Thanks

Replies are listed 'Best First'.
Re: Email::MIME won't send email to Bcc addresses
by tobyink (Canon) on Jan 11, 2012 at 11:44 UTC

    The BCC (blind carbon copy) "header" is not really an e-mail header. Clearly, it cannot be an e-mail header, because if it were, then recipients could examine it, and would no longer be "blind". Rather, BCC is a concept used by mail user agents, and usually implemented to that it appears (to end users) to be a header.

    Firstly, you need to understand that the message headers are not used to route the message to its recipients - they are purely informational. Instead, so called envelope addresses (part of SMTP) are used.

    And so, to implement BCC, what mail clients do, is simply send the e-mail to the intended recipient using the envelope address, but without adding any message header.

    In your particular case, what you need to do is:

    1. When constructing the message (Email::MIME->create), do not add a BCC header.
    2. When sending the message (sendmail), add an extra option, to (just like your current from option) which takes as its value an arrayref of all the e-mail addresses to which the e-mail should be sent. This includes not just the recipients you want to BCC it to, but also the non-blind recipients (To, CC).

    Something along these lines (though it isn't clear from your example what exactly $email_cc and $email_bcc contain - a single address, a comma-separated list, etc).

    my $email = Email::MIME->create( header_str =>[ To => $email_to, Cc => $email_cc, From => $email_from, Subject => $email_subject ], body_str =>$email_body, attributes => { content_type => 'text/html', charset => 'utf8', encoding => 'quoted-printable' } # ... try { sendmail( $email, { to => [$email_to, $email_cc, $email_bcc], from => $email_from, transport => Email::Sender::Transport::SMTP->new({host => $ +SMTP_HOSTNAME,port => $SMTP_PORT}) } ); } catch { print $_->message};

      Thanks for the responses all. Now that you've explained it, it makes perfect sense. Any email address which is in the

       to => [ .. ]

      list, but not in the "To" or "Cc" header is effectively a Bcc'd address. Needless to say, Email::MIME works fine. Thanks again !

Re: Email::MIME won't send email to Bcc addresses
by rjbs (Pilgrim) on Jan 11, 2012 at 12:39 UTC

    First off, it's Email::Sender that provides the "sendmail" method that you're talking about, not Email::MIME.

    This question comes up from time to time. I have written an explanation up already, on the Email::Sender github wiki.

    rjbs
      Great , now move it to the pod :)
Re: Email::MIME won't send email to Bcc addresses
by Anonymous Monk on Jan 11, 2012 at 10:11 UTC

    Try using try_to_sendmail instead :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://947314]
Approved by GrandFather
Front-paged by moritz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2020-03-31 08:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    To "Disagree to disagree" means to:









    Results (180 votes). Check out past polls.

    Notices?