本文介绍了Perl Net :: SMTP电子邮件大小问题,同时使用html格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

有时电子邮件大小在 1mb 。有什么办法可以减少电子邮件的大小,而不减少数据量。我不希望邮件作为附件。我使用outlook打开邮件。

解决方案

你应该使用通过电子邮件发送附件

 #!/ usr / bin / perl 
使用Mail :: Sender

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

$ subject ='这是一个测试电子邮件';
$ 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 =>'附件;
filename =File.zip; type =ZIP archive',
file =>$文件,
});

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

或使用MIME :: Lite

 使用MIME :: Lite; 

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

###添加ZIP文件
$ msg-> attach(
Type =>'application / zip',
Path => $ my_file_zip ,
Filename => $ your_file_zip,
Disposition =>'附件'
)或死添加$ file_zip错误$!\\\
;

###发送消息
$ msg-> send('smtp',$ mail_host,Timeout => 60);


I am sending an email via SMTP in perl . The email contains some tables,links and lists.I am using html format data.

$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;

Sometimes the email size is too large around 1mb. Is there any way I can reduce the size of email without reducing the amount of data.I do not want the message as an attachment. I use outlook to open the mails.

解决方案

You should use Mail::Sender for sending attachments through email

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

$to = '[email protected],[email protected]';
$sender =new Mail::Sender {
        smtp => 'smtp.mailserver.com',
        from => '[email protected],
        });

$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();

or using 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);

这篇关于Perl Net :: SMTP电子邮件大小问题,同时使用html格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 22:51