使用 Perl 透過電子郵件傳送附件


如果您想透過 Perl 在電子郵件中傳送附件,則可以使用以下指令碼 −

#!/usr/bin/perl
use MIME::Lite;
$to = 'abcd@gmail.com';
$cc = 'efgh@mail.com';
$from = 'webmaster@yourdomain.com';
$subject = 'Test Email';
$message = 'This is test email sent by Perl Script';
$msg = MIME::Lite-=>new(
   From => $from,
   To => $to,
   Cc => $cc,
   Subject => $subject,
   Type => 'multipart/mixed'
);
# Add your text message.
$msg->attach(
   Type => 'text',
   Data => $message
);
# Specify your file as attachement.
$msg->attach(Type => 'image/gif',
   Path => '/tmp/logo.gif',
   Filename => 'logo.gif',
   Disposition => 'attachment'
);
$msg->send;
print "Email Sent Successfully\n";

您可以在電子郵件中使用 attach() 方法附加任意數量的檔案。

更新於: 2019 年 11 月 29 日

2K+ 次瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.