使用Mail::Sender發送帶圖片的html郵件

來源:互聯網
上載者:User

標籤:

需要指出的一定要保持編碼的一致,否則會導致要麼html亂碼,或者主題亂碼。如果有多個圖片,可以採用多個Attach,html調用的圖片名稱為Attach中定義的。

:

#!/usr/bin/perluse strict;use warnings;use Config::Tiny;use FindBin;use Mail::Sender;my $configFile = "$FindBin::Bin/config.ini";my $configNew  = Config::Tiny->new;my $configRead = $configNew->read($configFile);my $configMail = $configRead->{‘mailInfo‘};eval {    ( new Mail::Sender )->OpenMultipart(        {            from        => "$configMail->{‘from‘}",            to          => "$configMail->{‘to‘}",            smtp        => "$configMail->{‘smtp‘}",            auth        => ‘LOGIN‘,            TLS_allowed => ‘0‘,            authid      => "$configMail->{‘user‘}",            authpwd     => "$configMail->{‘passwd‘}",            subject     => "$configMail->{‘title‘}",            boundary    => ‘boundary-test-1‘,            multipart   => ‘related‘,            encoding    => "7bit",         }      )->Part( { ctype => ‘multipart/alternative‘ } )->Part(        {            ctype       => ‘text/html;charset=utf-8‘,            disposition => ‘NONE‘,            msg         => <<‘*END*‘} )<html>    <head>        <title>xxxxx</title>        <style>            h1 {font-size:20px; color: green}        </style>    </head><center><h1>###圖片一###</h1><img src="cid:img1"></center></html>*END*->EndPart("multipart/alternative")->Attach(        {            description => ‘c\‘s png‘,            ctype       => ‘image/png‘,            encoding    => ‘base64‘,            disposition =>              "inline; filename=\”test.png\";\r\nContent-ID: <img1>",            file => ‘./test.png‘        }  )->Close();} or print "Error sending mail: $Mail::Sender::Error\n”;

config.ini

[mailInfo]to = [email protected]163.comfrom = [email protected]163.comsmtp = smtp.163.comuser = [email protected]163.compasswd = passtitle = 標題

 

使用Mail::Sender發送帶圖片的html郵件

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.