免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 5743 | 回复: 15
打印 上一主题 下一主题

perl发送html的邮件 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-02-13 19:18 |只看该作者 |倒序浏览
现在想在perl中实现发送html的功能,但是要在接收到邮件的中显示出一个背景。不知道怎么做,望大家此赐教。
在网上搜到这样的解决形式
#!/usr/lib/perl
use strict;

my($r_mail) = 'recipients@aaa.net';
my($s_mail) = 'sender@bbb.com';
my($subject) = 'subject';

open(MAIL,'|/usr/lib/sendmail -t');
select(MAIL);

print<<"END_TAG";
To: $r_mail
From: $s_mail
Subject: $subject

<html><body><a href=#>邮件内容</a></body></html>

END_TAG


可是把背景图放到body中 没成功?
望大家给点思路。 谢谢~

论坛徽章:
0
2 [报告]
发表于 2007-02-13 19:59 |只看该作者

回复 1楼 怪怪虎 的帖子

Hi,

try to use CPAN module MIME::Lite.

#Send an HTML document... with images included!
$msg = MIME::Lite->new(
    To      =>'you@yourhost.com',
    Subject =>'HTML with in-line images!',
    Type    =>'multipart/related'
);
$msg->attach(Type => 'text/html',
    Data => qq{ <body>
    Here's <i>my</i> image:
    <img src="cid:myimage.gif">
    </body> }
);
$msg->attach(Type => 'image/gif',
    Id   => 'myimage.gif',
    Path => '/path/to/somefile.gif',
);
$msg->send();



-- ulmer

论坛徽章:
0
3 [报告]
发表于 2007-02-13 20:03 |只看该作者
Thanks.
I will try.
would you please give me some more details or some documents.


Thanks very much.

论坛徽章:
0
4 [报告]
发表于 2007-02-13 20:13 |只看该作者
执行 perl s4.pl后的提示:
<H1>Software error:</H1>
<CODE>[Tue Feb 13 06:11:28 2007] HTML.pm: Can't locate MIME/Lite/HTML.pm in @INC
(@INC contains: /opt/x11r6/lib/perl5/5.00503/sun4-solaris /opt/x11r6/lib/perl5/
5.00503 /opt/x11r6/lib/perl5/site_perl/5.005/sun4-solaris /opt/x11r6/lib/perl5/s
ite_perl/5.005 .) at s4.pl line 5.
BEGIN failed--compilation aborted at s4.pl line 5.
</CODE>
<P>
For help, please send mail to this site's webmaster, giving this error message
and the time and date of the error.

[Tue Feb 13 06:11:28 2007] s4.pl: [Tue Feb 13 06:11:28 2007] HTML.pm: Can't loca
te MIME/Lite/HTML.pm in @INC (@INC contains: /opt/x11r6/lib/perl5/5.00503/sun4-s
olaris /opt/x11r6/lib/perl5/5.00503 /opt/x11r6/lib/perl5/site_perl/5.005/sun4-so
laris /opt/x11r6/lib/perl5/site_perl/5.005 .) at s4.pl line 5.
[Tue Feb 13 06:11:28 2007] s4.pl: BEGIN failed--compilation aborted at s4.pl lin
e 5.
ihgpweb: whichi perl
ksh: whichi:  not found
ihgpweb: perl -v

This is perl, version 5.005_03 built for sun4-solaris

Copyright 1987-1999, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5.0 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'.  If you have access to the
Internet, point your browser at http://www.perl.com/, the Perl Home Page.

论坛徽章:
0
5 [报告]
发表于 2007-02-13 20:22 |只看该作者
原帖由 怪怪虎 于 2007-2-13 20:03 发表
Thanks.
I will try.
would you please give me some more details or some documents.


Thanks very much.


Install MIME::Lite
perldoc MIME::Lite
Some background about Mail Header and Body is big benifit for you.   
http://en.wikipedia.org/wiki/Email
http://dsv.su.se/jpalme/ietf/mhtml.html
related Mail RFC

论坛徽章:
0
6 [报告]
发表于 2007-02-13 20:32 |只看该作者
这个问题LZ问对了,ulmer是这方面的专家,

论坛徽章:
0
7 [报告]
发表于 2007-02-13 21:57 |只看该作者

回复 5楼 ulmer 的帖子

Another question is that if I want to install MIME::Lite, I must be the root user?

论坛徽章:
0
8 [报告]
发表于 2007-02-13 22:03 |只看该作者
原帖由 怪怪虎 于 2007-2-13 21:57 发表
Another question is that if I want to install MIME::Lite, I must be the root user?


yes!

论坛徽章:
0
9 [报告]
发表于 2007-02-13 22:14 |只看该作者
原帖由 ulmer 于 2007-2-13 22:03 发表


yes!


bad new to me~
I am not the administrator.
would you please suggest another advice about this problem.

论坛徽章:
0
10 [报告]
发表于 2007-02-13 23:11 |只看该作者
原帖由 怪怪虎 于 2007-2-13 22:14 发表


bad new to me~
I am not the administrator.
would you please suggest another advice about this problem.


Yes.
as I mentioned, if you are familiar with email header and body and you can
self create the multiple-mimepart email.

But I think it's very difficult for you.

-- ulmer
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP