Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Sending Mail from Perl Script

by thezip (Vicar)
on Nov 20, 2007 at 01:45 UTC ( #651834=note: print w/ replies, xml ) Need Help??


in reply to Sending Mail from Perl Script

  • One thing that is definitely wrong is that you are not using strict nor warnings! All bets are off until you do this...

  • Try using the SMTP send method and setting the Debug=>1 flag. This could give you some additional information to work with (NOTE: this code is mostly right out of the MIME::Lite perldocs),
    use strict; use warnings; use MIME::Lite; ### Create a new multipart message: my $msg = MIME::Lite->new( From =>'me@myhost.com', To =>'you@yourhost.com', Cc =>'some@other.com, some@more.com', Subject =>'A message with 2 parts...', Type =>'multipart/mixed' ); ### use Net:SMTP to do the sending $msg->send('smtp','some.host', Debug=>1 );

Where do you want *them* to go today?


Comment on Re: Sending Mail from Perl Script
Download Code
Re^2: Sending Mail from Perl Script
by Niner710 (Sexton) on Apr 30, 2008 at 04:41 UTC
    I submitted this awhile ago and haven't been able to get back to it now. I modified my script to be like this...
    use strict; use warnings; use MIME::Lite; my $user = 'james@gmail.com'; my $pass = 'james12'; my $msg = MIME::Lite->new( From =>'James', To =>'james@hotmail.com', CC =>'', Subject =>'yah it worked', Type =>'Hello world' ); MIME::Lite->send('smtp','smtp.gmail.com:465', AuthUser=>$user, AuthPass=>$pass);
    Yet, I still can't connect correctly. Everything compiles ok but the email doesn't get sent at all. Can anyone tell me why?

      Have you tried enabling Debug as I suggested? What were the resulting messages?

      This might be a natural next step in the troubleshooting process.


      Your wish is my commandline.
        Hi, Yes, I tried the Debug=>1 option and got an error "Can't call method auth on an undefined value". When I tried to do it your way, it seems like the program hangs with the authorization part. I'm not sure why that is. My username and password are all correct. I've tried the username without the "@gmail.com" but still gives the same error. I'm wondering if I need SSL or anything for gmail. Can't seem to get my yahoo email account to work either. Maybe thats why the authorization is failing??
        use MIME::Lite; use Net::SMTP; $FROM='james@gmail.com'; $TO='james@hotmail.com'; $subject='TESTING 123'; $SMTPUSER='james@gmail.com'; $SMTPPASS='james1234'; $message_text='testing'; my $msg = MIME::Lite->new(From => $FROM,To => $TO,Subject => $subject, +Type => 'multipart/alternative'); my $smtp = new Net::SMTP('smtp.gmail.com:465', Timeout => 15, Debug => + 1); $smtp->auth($SMTPUSER, $SMTPPASS); $smtp->mail($FROM); $smtp->to($TO); $smtp->data($msg->as_string); $smtp->quit;

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2014-07-23 05:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (133 votes), past polls