Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

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

Replies are listed 'Best First'.
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 (Chaplain) 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/

    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 (Canon) 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 = ""; my $from_address = ''; my $to_address = ''; 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 (Chaplain) 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 => '', to => '', 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.



      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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://986941]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2018-05-20 23:38 GMT
Find Nodes?
    Voting Booth?