User Tools

Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

perl:mime-lite-sample [2020-02-15 00:57] (current)
Line 1: Line 1:
  
 +=====MIME::​Lite sample=====
 +
 +<code perl mail.pl>
 +#​!/​usr/​bin/​env perl
 +
 +use strict;
 +use MIME::Lite;
 +use MIME::​Base64 qw(encode_base64);​
 +use Encode qw(decode encode);
 +
 +my $from = '​some@sender.org';​
 +my $to = '​some@bare.com';​
 +my $subject = 'Hello Привет';​
 +
 +$msg = MIME::​Lite->​new(
 +        From     => $from,
 +        To       => $to,
 +        Subject ​ => "​=?​UTF-8?​B?"​ . encode_base64($subject,​ ""​) . "?​=",​
 +        Type     => '​multipart/​mixed',​
 +);
 +
 +$msg->​attach(
 +      Type     => '​text/​plain;​ charset=UTF-8', ​
 +      Data     => "​Привет! The attachment contains your file"
 +);
 +
 +#​$msg->​print(\*STDOUT);​
 +#​$msg->​print_header(\*STDOUT);​
 +#​$msg->​print_body(\*STDOUT);​
 +
 +my $server = "​mx8.lazurit.com";​
 +
 +#​$msg->​send; ​
 +$msg->​send('​smtp',​ $server, Timeout => 60, Debug => 1);
 +print "Mail Sent\n";​
 +
 +#EOF
 +</​code>​
 +
 +----
 +[<>]