send email using perl

 

If you are using windows system, there is no sendmail tool. At this point you can use perl's MIME:Lite module as a mail client to send mail.

Here we directly use cpan to install (requires root permissions) without downloading:

$ cpan -i MIME::Lite
……
  /usr/bin/make install  -- OK

Document address: http://search.cpan.org/~rjbs/MIME-Lite-3.030/lib/MIME/Lite.pm

also need to be installed

 

use MIME::Lite;
 
#Receive mailbox, here I set it as my QQ mailbox, you need to modify it to your own mailbox 
$to = ' [email protected] ' ;
 # CC, multiple separated by commas
# $cc = '[email protected], [email protected]';
 
# 
Sender's mailbox $from = ' [email protected] ' ;
 #Title $subject = ' Rookie Tutorial Perl Sending Email Test ' ;
 $message = ' This is an email sent by Perl, using the MIME::Lite module . ' ;

 
$msg = MIME::Lite->new(
                 From     => $from,
                 To       => $to,
                 Subject  => $subject,
                 Data     => $message
                 );
 
$user='[email protected]';
$pass = '123456'; 

$res = $msg -> send ( ' smtp ' , " smtp.163.com " ,AuthUser=> $user ,AuthPass=> $pass );
     if ( $res ){
     print  " Mail sent successfully\n " ;
    } else {
     print  " Failed to send mail\n " ;
    }    

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324997473&siteId=291194637