home PYTHONJAVA
 

Perl send mail

If your program is running on a Linux/Unix system, you can use the sendmail tool in Perl to send mail.

The following is a simple script example for sending mail:

Instance

#!/usr/bin/perl # Receive the mailbox, here I set it as my QQ mailbox, you need to regulate it as your own mailbox $to= ' larrypage@google.Com'; #sender's mailbox $from = ' legit@welookups.Com'; #name $challenge = ' Programming Tutorial Perl Send Mail Test'; $message = ' This is a message despatched the use of/usr/sbin/sendmail -t"); # mail header print MAIL "To: $ton" ; print MAIL "From: $fromn" ; print MAIL "Subject: $problemnn"; # Mailbox Information print MAIL $message; near(MAIL); print "Email sent effectivelyn";

Execute the above program, the output is:

Mail sent successfully

After joining the whitelist, you could procure mail for the most part.

Send HTML designed messages

We can include Content-kind: literary substance/htmln to the header of the message to send a HTML-designed message, as demonstrated inside the accompanying case:

Instance

#!/usr/bin/perl # Receive the mailbox, here I set it as my QQ mailbox, you want to alter it as your very own mailbox $to= ' larrypage@google.Com'; #sender's mailbox $from = ' respectable@welookups.Com'; #title $concern = ' Programming Tutorial Perl Send Mail Test'; $message = ' <h1>This is a message despatched using Perl<h1><p> Hello, I am from the rookie educational at http://www.Welookups. Com. </p>'; open(MAIL, "problemn" ; print MAIL "Content-type: text/htmln"; # Mailbox Information print MAIL $message; close(MAIL); print "Email sent efficientlyn";

Here we use cpan to install immediately (calls for root privileges), no download:

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

After the set up is successful, allow's reveal an instance:

Instance

#!/usr/bin/perl use MIME::Lite; # Receive the mailbox, right here I set it as my QQ mailbox, you need to adjust it as your personal mailbox $to= ' larrypage@google.Com'; # CC, separated by means of commas # $cc = 'test1@welookups.Com, test2@welookups.Com'; #sender's mailbox $from = ' legitimate@welookups.Com'; #name $subject = ' Programming Tutorial Perl Send Mail Test'; $message = ' This is a message sent the use of Perl, the usage of the MIME::Lite module. '; $msg= MIME::Lite< /span>->new( From => $from, To => $to, Cc => $cc, Subject => $challenge, Data => $message ); $msg->ship; print "Email sent efficaciouslyn";

We can upload Content-type: text/htmln to the header of the message to ship an HTML-formatted message, as proven within the following example:

Instance

#!/usr/bin/perl use MIME::Lite; # Receive the mailbox, right here I set it as my QQ mailbox, you want to regulate it as your very own mailbox $to= ' larrypage@google.Com'; # CC, separated by commas # $cc = 'test1@welookups.Com, test2@welookups.Com'; #sender's mailbox $from = ' respectable@welookups.Com'; #title $issue = ' Programming Tutorial Perl Send Mail Test'; $message = ' <h1>This is a message despatched using Perl<h1><p> uses the MIME::Lite module. </p><p>From the rookie tutorial, the address is: http://www.Welookups.Com. </p>'; $msg= MIME::Lite< /span>->new( From => $from, To => $to, Cc => $cc, Subject => $concern, Data => $message ); # Add header records $msg->attr("content-type" => "text/html"); $msg->send; print "Email despatched efficaciouslyn";

Send a message with an attachment

Send an instance of an electronic mail with an attachment as follows:

Instance

#!/usr/bin/perl use MIME::Lite; # Receive the mailbox, right here I set it as my QQ mailbox, you need to regulate it as your own mailbox $to= ' larrypage@google.Com'; # CC, separated via commas # $cc = 'test1@welookups.Com, test2@welookups.Com'; #sender's mailbox $from = ' respectable@welookups.Com'; #identify $challenge = ' Programming Tutorial Perl Send Mail Test'; $message = ' This is a message despatched using Perl, the usage of the MIME::Lite module, which includes attachments. '; $msg= MIME::Lite< /span>->new( From => $from, To => $to, Cc => $cc, Subject => $problem, Type => 'multipart/blended' # attachment tag );$msg->attach ( Type => 'TEXT', Data => $message );# Specify attachment data $msg->connect(Type => 'TEXT', Path => './welookups.Txt', # underneath the contemporary directory Filename => 'welookups.Txt', Disposition => 'attachment' ); $msg->ship; print "Email despatched successfullyn";





welookups is optimized for learning.© welookups. 2018 - 2019 All Right Reserved and you agree to have read and accepted our term and condition.