【问题标题】:Perl Net::SMTP Email Size issue while using html format使用 html 格式时的 Perl Net::SMTP 电子邮件大小问题
【发布时间】:2013-01-28 10:33:31
【问题描述】:

我在 perl 中通过 SMTP 发送电子邮件。该电子邮件包含一些表格、链接和列表。 我使用的是html格式数据。

$smtp->data();
$smtp->datasend("MIME-Version: 1.0\nContent-Type: text/html; charset=UTF-8 \n\n<H1>");
$smtp->datasend("$message");
...
$smtp->dataend();
$smtp->quit;

有时1mb 附近的电子邮件太大。有什么办法可以在不减少数据量的情况下减小电子邮件的大小。我不希望将邮件作为附件。我用outlook打开邮件。

【问题讨论】:

  • 我使用 gzip 对其进行了压缩,但问题是如何将其发送到 Outlook 以便正确显示。
  • Outlook 可能足够聪明,可以内联显示。许多 MUA 会内联显示压缩后的文本文件。

标签: perl email smtp


【解决方案1】:

您应该使用Mail::Sender 通过电子邮件发送附件

#!/usr/bin/perl
use Mail::Sender

$to = 'email1@example1.com,email2@example2.com';
$sender =new Mail::Sender {
        smtp => 'smtp.mailserver.com',
        from => 'script@somedomain.com,
        });

$subject = 'This is a Test Email';
$sender->OpenMultipart({
        to      => "$to",
        subject => "$subject",
        });

$sender->Body;
$sender->SendLineEnc("Test line 1");
$sender->SendLineEnc("Test line 2");

$sender->Attach({
        description     => 'Test file',
        ctype           => 'application/x-zip-encoded',
        encoding        => 'Base64',
        disposition     => 'attachment;
        filename="File.zip"; type="ZIP archive"',
        file            => "$file",
        });

$sender->Close();
exit();

或使用 MIME::Lite

use MIME::Lite;

$msg = MIME::Lite->new (
  From => $from_address,
  To => $to_address,
  Subject => $subject,
  Type =>'multipart/mixed'
) or die "$!\n";

### Add the ZIP file
$msg->attach (
   Type => 'application/zip',
   Path => $my_file_zip,
   Filename => $your_file_zip,
   Disposition => 'attachment'
) or die "Error adding $file_zip: $!\n";

### Send the Message
$msg->send('smtp', $mail_host, Timeout=>60);

【讨论】:

  • 感谢您的回答。我只是修改了一些数据以减小大小。
  • 好的。但是您是否尝试过上述解决方案?它有效吗?因为我没试过。
  • 我没有尝试过,因为我不希望它成为附件。但是附件也适用于 smtp,我之前在我的一个代码中使用过它。
  • 是的,文本附件适用于 smtp。但对于 zip 文件或二进制文件附件,我认为您需要上述模块。
  • 您能否更新您的问题,提到您不希望它作为附件。
猜你喜欢
  • 2018-01-16
  • 2014-06-23
  • 1970-01-01
  • 1970-01-01
  • 2012-06-29
  • 1970-01-01
  • 1970-01-01
  • 2015-11-03
  • 1970-01-01
相关资源
最近更新 更多