I am trying to use some Perl that I last used some years ago to send an e-mails.
It seems to have got ‘rusty’ as it no longer works and I cannot see why.The code follows.
$smtp = Net::SMTP->new($$ref_host_em);
print "[send_em] smtp <$smtp>\n";
$sm_ma = $smtp->mail($$ref_from_em);
$en = 0;
$en = Win32::GetLastError();
$en_f = Win32::FormatMessage($en);
print "[send_em] A en <$en> <$en_f> result of smtp send ma <$sm_ma>\n"
+;
#$sm_to = $smtp->to ($to_em_item);
$sm_to = $smtp->to ($$ref_from_em);
$en = 0;
$en = Win32::GetLastError();
$en_f = Win32::FormatMessage($en);
print "\n[send_em] B en <$en> <$en_f> result of smtp send ma <$sm_ma>
+ to <$sm_to> \n";
$sm_da = $smtp->data();
$en = 0;
$en = Win32::GetLastError();
$en_f = Win32::FormatMessage($en);
print "\n[send_em] C en <$en> <$en_f> result of smtp send ma <$sm_ma>
+ to <$sm_to> da <$sm_da>\n";
$sm_se = $smtp->datasend($message_body);
$en = 0;
$en = Win32::GetLastError();
$en_f = Win32::FormatMessage($en);
print "\n[send_em] D en <$en> <$en_f> result of smtp send ma <$sm_ma>
+ to <$sm_to> da <$sm_da> se <$sm_se>\n";
$sm_ed = $smtp->dataend();
$en = 0;
$en = Win32::GetLastError();
$en_f = Win32::FormatMessage($en);
print "\n[send_em] E en <$en> <$en_f> result of smtp send ma <$sm_ma>
+ to <$sm_to> da <$sm_da> se <$sm_se> ed <$sm_ed>\n";
The results from this are below.
As can be seen I get the ‘handle is invalid’ error message continuously after and including the $smtp->to line.
This is even when the data used for the $smtp->to is the identical to that used for the successful $smtp->mail.
I think that the $smtp = Net::SMTP->new is OK since as well as getting a ‘value’ for $smtp I get an error message if I use this code when the PC is not connected to the Internet.
Can anyone suggest what is going wrong and how to cure this?
send_em smtp <Net::SMTP=GLOB(0x1d66660)>
send_em A en <0> <The operation completed successfully.> result of smtp send ma <>
send_em B en <6> <The handle is invalid> result of smtp send ma <> to <0>
send_em C en <6> <The handle is invalid.> result of smtp send ma <> to <0> da <>
send_em D en <6> <The handle is invalid.> result of smtp send ma <> to <0> da <> se <0>
send_em E en <6> <The handle is invalid.> result of smtp send ma <> to <0> da <> se <0> ed <0>
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.