send email through a perl script.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lilly07
    New Member
    • Jul 2008
    • 89

    send email through a perl script.

    I am running a perl script under linux environment. I am looking for a possibility of sending mail to a set of pepole when something goes wrong. Is is possible to do? Thanks.
  • lilly07
    New Member
    • Jul 2008
    • 89

    #2
    I found a small example as below and tried.

    Code:
    #!/usr/bin/perl
    
    my $to='xyz@hotmail.com';
    my $from='xyz@hotmail.com';
    my $subject='Low Disk Space';
    
    # send email using UNIX/Linux sendmail
    open(MAIL, "|/usr/sbin/sendmail -t");
    my $out = "testing";
    
     
    ## Mail Header
    print MAIL "To: $to\\n";
    print MAIL "From: $from\\n";
    print MAIL "Subject: $subject\\n";
     
    ## Mail Body
    print MAIL $out;
     
    close(MAIL);

    When I execute the code, I get a message as below:
    Code:
    No recipient addresses found in header
    How to resolve? Can't I use any public domains like hotmail etc.. or do I have to set up anything in my linux server. Please let me know. Thanks.

    Comment

    • KevinADC
      Recognized Expert Specialist
      • Jan 2007
      • 4092

      #3
      You need to remove the extra backslashes in these lines:

      Code:
      print MAIL "To: $to\\n";
      print MAIL "From: $from\\n";
      print MAIL "Subject: $subject\\n";
      Should be:

      Code:
      print MAIL "To: $to\n";
      print MAIL "From: $from\n";
      print MAIL "Subject: $subject\n\n";

      Note the two \n\n after subject, that is necessary the way you are doing it.

      Comment

      • numberwhun
        Recognized Expert Moderator Specialist
        • May 2007
        • 3467

        #4
        In addition to the example that you found, you can also check out the Net::SMTP module from CPAN. Its also a good way to go.

        Regards,

        Jeff

        Comment

        • KevinADC
          Recognized Expert Specialist
          • Jan 2007
          • 4092

          #5
          Originally posted by numberwhun
          In addition to the example that you found, you can also check out the Net::SMTP module from CPAN. Its also a good way to go.

          Regards,

          Jeff
          I think they got that suggestion on Devshed.

          Comment

          • eWish
            Recognized Expert Contributor
            • Jul 2007
            • 973

            #6
            In this thread I posted some code that would send an email with out the use of additional modules.

            --Kevin

            Comment

            Working...