If your program runs on Linux/Unix, you can use it in Perl
sendmail
tool to send mail.
The following is a simple script example for sending mail: Execute the above program, and the output is as follows: Under normal circumstances, the above mail will be intercepted by QQ Mail, we can add it to the whitelist, the mode of operation can be clicked: https://kf.qq.com/faq/120322fu63YV130805rYRFzu.html After joining the whitelist, you can receive email normally. We can add it to the header After the execution is successful, you can view the contents of the message. If you are using a window system, no We use it directly here. After the installation is successful, let’s demonstrate an example: After the execution is successful, you can view the contents of the message. We can add it to the header After the execution is successful, you can view the contents of the message. An example of sending a message with an attachment is as follows: Filename= > ‘runoob.txt’,Disposition= >’ attachment’) in the current directory; $msg- > send;print “email sent successfullyn” After the execution is successful, you can view the contents of the message. You can do this by using multiple 5.40.1. Example #
#!/usr/bin/perl# Receiving email, I set it as my QQ
Email, you need to modify it to your own email $to='429240967@qq.com';
#Sender email$from='test@runoob.com';#title$subject='Novice Tutorial
Perl Send Email Test';$message='This is a letter using Perl
sent email.';open(MAIL,"\|/usr/sbin/sendmail -t");#
Email header printMAIL"To:$to\\n";printMAIL"From:$from\\n";printMAIL"Subject:$subject\\n\\n";#
Email information printMAIL$message;close(MAIL);print"Email sent successfully\\n";
Email sent successfully
Send a message in HTML format #
Content-type:
text/html\n
to send an emailin HTML format, an example is as follows: 5.40.2. Example #
#/ Usr/bin/perl # Receive email, here I set it as my QQ
Email, you need to modify it to your own email $to=' 429240967@qq.com '# Sender email
$from=' test@runoob.com '# Title $subject='Rookie Tutorial
Perl sending email test '$ Message='<h1>This is an email using Perl
Hello, I am from Cainiao Tutorial and my address is: http://www.runoob.com </ p> '; Open (MAIL, " |/usr/sbin/sendmail
-T ")#
Email header printMAIL "To: $to n"; PrintMAIL "From: $from n"; PrintMAIL "Subject: $subject n"; PrintMAIL "Content type:
Text/html n "#
Email information printMAIL $message; Close (MAIL); Print "Email sent successfully n";
Use the MIME::Lite module #
sendmail
tools. At this point, youcan use
perl
of
MIME:Lite
module to send mail as a mail client.
MIME:Lite
module download address is: MIME-Lite-3.030.tar.gz .
cpan
to install (root permission is required) without downloading:$ cpan -i MIME::Lite
……
/usr/bin/make install -- OK
5.40.3. Example #
#/ Usr/bin/perluse MIME:: Lite# Receiving email, I set it as my QQ here
Email, you need to modify it to your own email $to=' 429240967@qq.com '#
CC recipients, multiple separated by commas # $cc=' test1@runoob.com ,
test2@runoob.com '# Sender email $from=' test@runoob.com '# Title $subject='Rookie Tutorial
Perl sending email test '$ Message='This is an email sent using Perl, using
MIME:: Lite
Module$ Msg=MIME:: Lite ->new (From=>$from, To=>$to, Cc=>$cc, Subject=>$subject,
Data=>$message)$ Msg ->send; Print "Email sent successfully n";
Send a message in HTML format #
Content-type:
text/html\n
to send an emailin HTML format, an example is as follows: 5.40.4. Example #
#/ Usr/bin/perluse MIME:: Lite# Receiving email, I set it as my QQ here
Email, you need to modify it to your own email $to=' 429240967@qq.com '#
CC recipients, multiple separated by commas # $cc=' test1@runoob.com ,
test2@runoob.com '# Sender email $from=' test@runoob.com '# Title $subject='Rookie Tutorial
Perl sending email test '$ Message='<h1>This is an email using Perl
The email sent<h1><p>used MIME:: Lite
Module</ p> From the rookie tutorial, the address is: http://www.runoob.com </ p> '$ Msg=MIME::
Lite ->new (From=>$from, To=>$to, Cc=>$cc, Subject=>$subject, Data=>$message)#
Add header information $msg ->attr ("content type"=>"text/html")
$ Msg ->send; Print "Email sent successfully n";
Send a message with an attachment #
5.40.5. Example #
#/ Usr/bin/perluse MIME:: Lite# Receiving email, I set it as my QQ here
Email, you need to modify it to your own email $to=' 429240967@qq.com '#
CC recipients, multiple separated by commas # $cc=' test1@runoob.com ,
test2@runoob.com '# Sender email $from=' test@runoob.com '# Title $subject='Rookie Tutorial
Perl sending email test '$ Message='This is an email sent using Perl, using
MIME:: Lite
Module, including attachments$ Msg=MIME:: Lite ->new (From=>$from,
To=>$to, Cc=>$cc, Subject=>$subject, Type=>'multipart/mixed '#
Attachment marking)$ Msg ->attach (Type=>'TEXT ', Data=>$message)#
Specify attachment information $msg ->attach (Type=>'TEXT ', Path=>'./runoob. txt '#
$msg->attach
to add multiple attachments.