http://www.perlmonks.org?node_id=33488

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question: (mail and news)

Trying to send email; system is Windows. In particular, I'd like to use the Yahoo email service to send the mail. Any help appreciated.

Originally posted as a Categorized Question.

  • Comment on how do i send an email with perl in window system

Replies are listed 'Best First'.
Re: how do i send an email with perl in window system
by sago (Scribe) on Jun 29, 2007 at 10:14 UTC

    Please see the below two programs to send mail through perl using activeperl on windows.

    The first uses Mail::Sendmail and the second uses MIME::Lite.

    use Mail::Sendmail; my $MailFrom = 'test@gmail.com'; my $to_list = 'john@gmail.com'; my $cc_list = 'frank@yahoo.com'; my $subject = "hello test"; my $message = "This email was generated automatically.\n"; sendmail( Smtp => 'mailtest.gmail.com', From => $MailFrom, To => $to_list, Cc => $cc_list, Subject => $subject, Message => $message, );
    use MIME::Lite; MIME::Lite->send('smtp', "mailtesthub.gmail.com", Timeout=>90); my $MailFrom = 'test@gmail.com'; my $to_list = 'john@gmail.com'; my $cc_list = 'frank@yahoo.com'; my $subject = "hello test"; my $message = "This email was generated automatically."; my $msg = MIME::Lite->new( From => $MailFrom, To => $to_list, Cc => $cc_list, Subject => $subject, Type => 'TEXT', Encoding => '7bit', Data => $message, ); $msg->send()
      You could also save yourself some vertical space and try (my) Net::SMTP::OneLiner. There is a lot of stuff it doesn't do, but it's nice for cron jobs and things.
      use strict; use Net::SMTP::OneLiner; send_mail( 'from@me', ['to1@you', 'to2@you'], "subject", "message\nmes +sage\nmessage\n" );

      -Paul

        Hello Paul, I was looking for this and I tried your steps exactly what you have stated above for sending emails in Perl using Net::SMTP::OneLiner. But unfortunately it is not working for me. I don't know what I have made wrong as I'm very new to Perl but just followed exactly your steps. Could you please let me know what I need to do in order to work? Thanks, Sachin
Re: how do i send an email with perl in window system
by iguane (Beadle) on Apr 11, 2001 at 12:29 UTC
    MIME::Lite works on Windows. If you have a sendmail program installed, you can use that:
    MIME:Lite->send( 'sendmail', "d:\\programs\\sendmail.exe" );
    Otherwise, you can tell it to use a remote mail server via smtp.
Re: how do i send an email with perl in window system
by idnopheq (Chaplain) on Apr 12, 2001 at 02:11 UTC

    A few non-Perl, Yahoo!-specific things to consider:

    • Sign up in the POP Access and Forwarding section of Options.
    • 'Need Help?' for POP3 access tells you what you need to use this access (server names, etc.)
    • You must authenticate when you send SMTP messages via their service.

    As for Perl, TIMTOWTDI. The combination of Mail::Sender (for the SMTP) and Mail::POP3Client (for the authentication) may work with Yahoo! mail without the need for SendMail. Both are available on ActiveState's PPM Package Repository.

Re: how do i send an email with perl in window system
by Anonymous Monk on Sep 21, 2000 at 23:17 UTC

    When facing similar things, I use the smtp method of Mail::Mailer (which depends on elements of the Net bundle).

    The following example sends an e-mail composed from a terminal window. Obviously you'd need to configure the variables to your situation.

    use Mail::Mailer; print "\nTo: "; $dest = <>; chomp $dest; print "Subject: "; $subj = <>; chomp $subj; print "\nBody:\n"; $body = <>; $mailer = Mail::Mailer->new( 'smtp', Server => 'pilot.msu.edu' ); $mailer->open( { From => 'Mr Grits <moranjon@pilot.msu.edu>', To => $dest, Subject => $subj, } ) or die "mailer->open failed: $!\n"; print $mailer $body; $mailer->close;
      Boy did I butcher that up - Try 2

      Well there are probablly others who could give a more elegant solution, but I used smtp method of Mail::Mailer (which depends on elemants of the Net bundle) when facing sowewhat similar thing. What this does is send an e-mail composed from a terminal window. You would need to change the smtp server to yours and the from line and also the top shebang line to something more appropriate for windows. Also the To, Subject and Body variables could be changed to your heart's content.

      mailtest.pl

      #!/usr/bin/perl -w use Mail::Mailer; print "\nTo: "; $dest = <STDIN>; chomp $dest; print "Subject: "; $subj = <STDIN>; chomp $subj; print "\nBody:\n"; $body = <STDIN>; $mailer = Mail::Mailer->new("smtp", Server=> "pilot.msu.edu"); $mailer->open( { From => 'Mr Grits <moranjon@pilot.msu.edu>', To => "$dest", Subject => "$subj" } ) or die "Couldnt do it: $!\n"; print $mailer $body; $mailer->close();


      Jonathan Moran (Colonel_Panic)
Re: how do i send an email with perl in window system
by acid06 (Friar) on Sep 22, 2000 at 02:36 UTC
    SendMail for Windows is available at DynamicState.

    Originally posted as a Categorized Answer.

Re: how do i send an email with perl in window system
by crazyinsomniac (Prior) on Nov 04, 2002 at 10:36 UTC

    Re: how do i send an email with perl in window system

    Originally posted as a Categorized Answer.

A reply falls below the community's threshold of quality. You may see it by logging in.