Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

sending e-mail using perl script

by artifact (Novice)
on Aug 12, 2012 at 07:54 UTC ( #986941=perlquestion: print w/ replies, xml ) Need Help??
artifact has asked for the wisdom of the Perl Monks concerning the following question:

greetings monks!!! I need to know how can one send an email to some address using a perl script. I am using windows 7 and I have my outlook configured with my yahoo account by the help of YPOP. thanks in advance

Comment on sending e-mail using perl script
Re: sending e-mail using perl script
by Corion (Pope) on Aug 12, 2012 at 08:27 UTC

    If you want to use Outlook to send mails, there is Mail::Outlook.

Re: sending e-mail using perl script
by thomas895 (Friar) on Aug 12, 2012 at 09:43 UTC

    While you could interface with Outlook, that's an unnecessary step, and adds complexity to the program. And you know how it goes with complex things: when they break, it's a pain to fix. See KISS.

    Instead, consider using something like Net::SMTP, and filling in the values Yahoo has given you for the server connection and authentication. Trust me, you will probably save yourself a big headache if you avoid Outlook.
    But it is your choice, and if you must, then so be it. Good luck with that, I know very little about Micro-Soft's many APIs, I'm afraid.

    Edit: s/mus/must/

    ~Thomas~
    confess( "I offer no guarantees on my code." );
Re: sending e-mail using perl script
by zentara (Archbishop) on Aug 12, 2012 at 12:01 UTC
Re: sending e-mail using perl script
by rpnoble419 (Pilgrim) on Aug 12, 2012 at 13:40 UTC
    I use Mail::Sender under Windows 7 and Windows Server 2003 and 2008. Works every time I have a valid email address to send To...
Re: sending e-mail using perl script
by roho (Monsignor) on Aug 12, 2012 at 15:49 UTC
    Mime::Lite is a good choice. The following program uses it to send both text and attachments.

    #!/usr/bin/perl use MIME::Lite; # Set this variable to your smtp server name my $ServerName = "smtp.comcast.net"; my $from_address = 'me@comcast.net'; my $to_address = 'me@hotmail.com'; my $subject = 'MIME Test: Text'; my $mime_type = 'text'; my $message_body = "Testing text in email.\n"; # Create the initial text of the message my $mime_msg = MIME::Lite->new( From => $from_address, To => $to_address, Subject => $subject, Type => $mime_type, Data => $message_body ) or die "Error creating MIME body: $!\n"; # Attach the text file my $filename = 'C:\tmp\test.txt'; my $recommended_filename = 'test.txt'; $mime_msg->attach( Type => 'application/text', Path => $filename, Filename => $recommended_filename ) or die "Error attaching text file: $!\n"; # encode body of message as a string so that we can pass it to Net::SM +TP. my $message_body = $mime_msg->body_as_string(); # Let MIME::Lite handle the Net::SMTP details MIME::Lite->send('smtp', $ServerName); $mime_msg->send() or die "Error sending message: $!\n";

    "Its not how hard you work, its how much you get done."

Re: sending e-mail using perl script
by Steve_BZ (Hermit) on Aug 12, 2012 at 19:04 UTC

    Hi Artifact,

    I use Mail::Sender from my code. Here's a test script to use it:

    #!/usr/bin/perl -w use strict; use Mail::Sender; my $sender = new Mail::Sender { auth => 'PLAIN', authid => 'your email userid', authpwd => 'your email userid password', smtp => 'your isp smtp server', port => 587, from => 'image@i-mageonline.com', to => 'you@yourdomain.com', subject => 'This is a test.', msg => 'Test Message Script', #file => '/home/image/Documents/Endoscopia/default.pdf', #debug => "/home/image/Documents/SendMailDebug.txt", #debug_level => 4, #timeout => 500, }; #my $result = $sender->MailFile({ my $result = $sender->MailMsg({ msg => $sender->{msg}, #file => $sender->{file}, }); print "$sender->{error_msg}\n>>>End.\n"; 1;

    You can customise the script.

    Have fun.

    It's well-functioned and intuitive.

    Regards

    Steve

      thanks everybody for the help. I found the Mail::Sender an easy one for a novice like me. I'll check other modules as well . I feel good having some wisdom !!!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (12)
As of 2014-04-24 11:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (565 votes), past polls