打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Mail attachment using perl
userphoto

2012.06.07

关注
Mail attachment using perl

Hello All,

My script collects information and writes it to a xls file and should mail it across.

I tested the first part of the script which writes the excel file , it does write the excel file fairly with expected data using Spreadsheet::WriteExcel module

Second part uses MIME::Lite , All I get is a mail with intended subject intact but without the attachment . Following is the code , I have googled and tried out many options , didn't go any further apart from receiving a mail without attachment.

use MIME::Lite;

$msg = MIME::Lite->new(
From => 'xx',
To => 'xx',
Subject => 'using module'
);

$msg->attach(
Type => 'application/xls',
Encoding => 'base64',
);
$msg->attach(
Path => '/tmp/hello.xls',
Filename => 'hello.xls',
Disposition => 'attachment'
);

$msg->send();

I am using RHEL 4 , Perl 5.8

Kindly advise me of what might be going wrong . Thanks in Advance.

Last edited by ++nick++; 02-28-2010 at 01:41 PM.
 
Quote:
Originally Posted by ++nick++
Hello All,

My script collects information and writes it to a xls file and should mail it across.

I tested the first part of the script which writes the excel file , it does write the excel file fairly with expected data using Spreadsheet::WriteExcel module

Second part uses MIME::Lite , All I get is a mail with intended subject intact but without the attachment . Following is the code , I have googled and tried out many options , didn't go any further apart from receiving a mail without attachment.

use MIME::Lite;

$msg = MIME::Lite->new(
From => 'xx',
To => 'xx',
Subject => 'using module'
);

$msg->attach(
Type => 'application/xls',
Encoding => 'base64',
);
$msg->attach(
Path => '/tmp/hello.xls',
Filename => 'hello.xls',
Disposition => 'attachment'
);

$msg->send();

I am using RHEL 4 , Perl 5.8

Kindly advise me of what might be going wrong . Thanks in Advance.
First forget about Excel and try to send a plain text attachment.

...

I haven't read the documentation, but are you sure you have to call the 'attach' method twice ? And are you sure the return value of the 'attach' method shouldn't be checked for errors ?

Last edited by Sergei Steshenko; 03-01-2010 at 05:25 AM.
Thanks for the reply,

I tried to mail a plain text file , it didnt work either , all I received is a mail without attachment , below is the code,

use MIME::Lite;

$mail = MIME::Lite->new(
From => 'xx',
To => 'xx',
Subject => 'mailing a text attachment using mime lite',
);

$mail -> attach(
Type => 'text/html',
Path => '<absolute path>',
Filename => 'file1',
Disposition => 'inline',
);

$mail -> send();

#END

Kindly advice
Try this

Hello nick,

Try the following code.

Code:
use strict;use warnings;use MIME::Lite;my $msg = MIME::Lite->new(    From    => 'xxx',    To      => 'xxx',    Subject => ' Test message',    Type    => 'multipart/mixed',);$msg->attach(    Type     => 'text',    Data     => "Here is the file",);$msg->attach(    Type     => 'text',    Path     => '/home/user/Documents/Assignment1',    Filename => 'Assignment1',);$msg->send;
Always mention the type of the data you going the send.

Thanks.

Last edited by karthi_27; 03-01-2010 at 05:15 AM.
Hello All,

Adding a line(Type => 'multipart/mixed',) to the code made all the difference , fine the code below ,

use MIME::Lite;

$mail = MIME::Lite->new(
From => 'ramkar',
To => 'ramkar',
Subject => 'mailing a text attachment using mime lite',
Type => 'multipart/mixed',
);

$mail -> attach(
Type => 'text/html',
Path => '/ms/user/r/ramkar/file1',
Filename => 'file1',
Disposition => 'attachment',
);

$mail -> send();

#END

Thanks All.
Hi,

Thanks karthi , I saw your post only after posting mine in which i expressed the need for mentioning Type , thanks anyways

Cheers
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
Sending Inline Images in e-mail with Mail::Sender and MIME::Lite
有关web页面内容文件强制下载代码整理
使用Python实现电子邮件群发功能
header中Content
Java使用POI导出Excel .xlsx提示文件格式或文件扩展名有误
Redmine中自动预览附件图片
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服