Reference;
http://www.perlmonks.org/?node_id=784574
用 $smtp->datasend 傳附檔內容時,因為 gmail 接收資料有長度限制,如果一次傳送大量資料會出錯。變通辦法是用 split 將資料分段送出。
use Net::SMTP::TLS;
use MIME::Lite;
$gmail_from = 'account@gmail.com';
@gmail_bcc_png = ('bcc@gmail.com');
$mail_subject = "<mail_subjuct>";
$msg = MIME::Lite->new(
From => $gmail_from,
To => $gmail_from,
Subject => $mail_subject,
Type =>'multipart/mixed',
);
$msg->attach(
Type => 'image/png',
Path => '<file full path>',
Filename => 'report1.png',
Disposition => 'attachment'
);
$smtp = new Net::SMTP::TLS(
'smtp.gmail.com',
Port => 587,
User => '<account@gmail.com>',
Password=> '<password>',
Timeout => 30
);
$smtp->mail($gmail_from);
$smtp->bcc(@gmail_bcc_png);
$smtp->data();
@tmp = split(/\n/, $msg->as_string);
foreach $line (@tmp) {
$line = $line . "\n";
$smtp->datasend( $line );
}
$smtp->dataend();
$smtp->quit;
沒有留言:
張貼留言