Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^3: Sending email on a Windows enviroment not using ActivePerl or StrawberryPerl

by chessgui (Scribe)
on Feb 02, 2012 at 14:51 UTC ( #951454=note: print w/replies, xml ) Need Help??


in reply to Re^2: Sending email on a Windows enviroment not using ActivePerl or StrawberryPerl
in thread Sending email on a Windows enviroment not using ActivePerl or StrawberryPerl

I had to do the login in this manual way because I had problems with the authentication (the method provided by the SMTP object simply did not work: I did some research and turned out that others are having similar problems on Win32). My original code has hard coded server and user names. Now I've tried to comprise things in one sub called 'sendmail'. I've tested this sub to the extent of sending one e-mail and it worked. The parameters to the sub should be obvious (set 'debug' to '0' if everything works fine, set it to '1' and you will get a verbose debug info with the commands the SMTP object sends to the server and the responses - in my case this proved to be very helpful):
use Net::SMTP; use MIME::Base64; # usage: sendmail(mailserver,username,password,from,to,subject,content +,debug); sub sendmail { my ($mail_server,$username,$password,$from,$to,$subject,$content,$debu +g)=@_; $smtp = Net::SMTP->new( $mail_server, Timeout => 30, Debug => $debug, ); $smtp->datasend("AUTH LOGIN\n"); $smtp->response(); $smtp->datasend(encode_base64($username)); $smtp->response(); $smtp->datasend(encode_base64($password)); $smtp->response(); $smtp->mail($from); $smtp->to($to); $smtp->data(); $smtp->datasend("To: $to\n"); $smtp->datasend("From: $from\n"); $smtp->datasend("Content-Type: text/html\n"); $smtp->datasend("Subject: $subject"); $smtp->datasend("\n"); $smtp->datasend($content); $smtp->datasend("\n"); $smtp->dataend(); $smtp->quit; }
  • Comment on Re^3: Sending email on a Windows enviroment not using ActivePerl or StrawberryPerl
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://951454]
help
Chatterbox?
[LanX]: yep
[erix]: or Ctrl-U to view current html :P
[LanX]: name not id
[LanX]: id isn't approved AFAIK
[LanX]: name works
erix feels silly for having actually tested that contiguous values make no difference in CLUSTERing a table (At least, in postges)
[LanX]: Perl Monks Approved HTML tags
[LanX]: erix and his postguess ...
[erix]: (Grrres...)
[dabella12]: I have a problem install tK on CeontOs using perl 5.24

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (10)
As of 2017-06-24 13:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (557 votes). Check out past polls.