Sending email using Perl

后端 未结 4 1733
温柔的废话
温柔的废话 2020-12-20 04:19

I’m trying to use Perl to send an email message. Basically I have a Perl script that prints out a report in a nice format. I want that report to be sent via email. How can I

4条回答
  •  粉色の甜心
    2020-12-20 04:58

    Simplest way without CPAN libraries:

    #!/usr/bin/perl
    
    $to = 'toAddress@xx.com';       # to address
    $from = 'fromAddress@xx.com';   # from address
    $subject = 'subject';           # email subject
    $body = 'Email message content';# message
    
    open(MAIL, "|/usr/sbin/sendmail -t");     
    print MAIL "To: $to\n";
    print MAIL "From: $from\n";
    print MAIL "Subject: $subject\n\n";
    print MAIL $body;    
    close(MAIL);
    
    print "Email Sent Successfully to $to\n";
    

提交回复
热议问题