Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

How to print the recipients address in my mail

by chandru210486 (Initiate)
on Oct 19, 2012 at 21:56 UTC ( #1000060=perlquestion: print w/ replies, xml ) Need Help??
chandru210486 has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I use Net::SMTP to send mail from my perl program. when i receive the mail, i am not able to see the recipient's address. I want to see the recipient's address in the mail. please let me know how i can do that. Below is my code. perl version used v5.8.8.

sub send_mail { my ($rpt_name) = @_; (my $volume, my $directories, my $file_name) = File::Spec->spl +itpath($rpt_name); my $from = "abc\@a.com"; my $to = "aa\@aa.com, bb\@bbbb.com"; my @EMAIL_RECIPIENTS = split(/[,;]/, $to); my $DATA1; $smtp = Net::SMTP->new($host , Debug => 1); $smtp->mail($from); foreach $recipient (@EMAIL_RECIPIENTS) { $smtp->to($recipient); } open(DATA1, $rpt_name) || die("Could not open the file"); my @csv = <DATA1>; close(DATA1); $smtp->recipient($to, { SkipBad => 1 }); $smtp->data(); $smtp->datasend("Subject: TEST MAIL \n\n @csv"); $smtp->dataend(); $smtp->quit; } exit;

Comment on How to print the recipients address in my mail
Download Code
Re: How to print the recipients address in my mail
by Old_Gray_Bear (Bishop) on Oct 19, 2012 at 22:49 UTC
    Whether the recipient address is displayed is function of the mail client.

    If your email is received by the correct addressee, then the To: header was correctly formatted. If the header is not displayed, then you need to get yourself a better set of client options.

    ----
    I Go Back to Sleep, Now.

    OGB

Re: How to print the recipients address in my mail
by tobyink (Abbot) on Oct 19, 2012 at 23:03 UTC

    You would probably be better off using something like Mail::Box because Net::SMTP is very low-level.

    But in answer to your question, mails sent by SMTP have two places where the recipient is specified: the so called "envelope header" which is part of the SMTP protocol itself (yes, I'm aware what the P stands for), and the "message header" which is part of the RFC 822 format (and successors).

    It is the message header which email clients display. They don't usually have access to the envelope header at all, unless the mail server makes part of it available to them (which is quite common; usually by reformatting parts of it and adding them to the message header). Net::SMTP is an SMTP implementation which doesn't concern itself with the formatting of the message itself at all.

    Anyway, to cut a long story short...

    $smtp->datasend("To: $to\nSubject: TEST MAIL\n\n@csv");
    1000066 and all that

      Thanks - It is working now.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2014-12-21 15:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (106 votes), past polls