[PerlChina] Fwd: 用Perl统计hao123网址之家首页的网站WEB服务器种类

陈学芹 robbiecn at gmail.com
Tue Aug 21 18:18:59 PDT 2007


在 07-8-21,Steven Zhu<stevenzyk at gmail.com> 写道:
> 你好,请教一下,perl可以发送大容量附件的邮件吗?20-30MB的
>
>
这个话题篇偏离了我这份原始邮件的主题:)

可以用MIME::Lite和Net::SMTP两个库实现,用MIME::Lite构建一封邮件,然后附件作为一个part
Attatch到邮件中,然后调用as_string方法.然后用Net::SMTP  send出去

参考代码:

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


$part = MIME::Lite->new(
                 Type     => 'text/plain',
                 Data     => $data_content,
                 Encoding => 'base64',
                 Disposition => 'inline',
                 );
$part->attr('content-type.charset' => 'GB2312');

### Add the text message part
$msg->attach($part) or die "Error adding the text message part: $!\n";

$mime_all = $msg->as_string;

$smtp = Net::SMTP->new(
	Host => $mail_host,
	Hello => $hello_string,
	Timeout => 30,
	#Debug => 1
);
$smtp->auth($user, $passwd);

$smtp->mail($to_address);

$smtp->data();
$smtp->datasend($mime_all);

$smtp->quit();


-- 
/*
*@author: chen xueqin
*@email: robbiecn at gmail.com
*@see: http://robbie.bokee.com
*@see: http://groups.google.com/group/fzlug
*@love: freedom,tux,open source
*/


More information about the China-pm mailing list