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 (Patriarch) 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 (Deacon) 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 (Cardinal) 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 (Bishop) 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 (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 => '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 !!!

      Hi How to pass parameter to the email subroutine, I need the value of parameter to be shown on the email subject and body. Thanks in advance

        What "email subroutine" are you talking about?

        Nowhere in this thread was such a subroutine posted, so maybe you wanted to reply to a different thread?

        If the "email subroutine" is in some code that you are not showing us, consider posting the relevant parts of the code. Also tell us how the code fails to do what you need, and also show us what you already tried and also how that failed for you.