免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
Sending Inline Images in e-mail with Mail::Sender and MIME::Lite

Sending Inline Images in e-mail with Mail::Sender (or getting them to print in Outlook)

by vroom (Pope)
on Mar 03, 2003 at 22:02 UTC ( #240171=perlquestion: print w/ replies, xml ) Need Help??
vroom has asked for the wisdom of the Perl Monks concerning the following question:

Hi I'm currently working on sending an HTML e-mail with inline images using Mail::Sender and running into problems. I can get the images to show up fine in Outlook but when I print the messages the images show up as the "not found" x's.

The code below is mostly shamelessly cut from the Mail::Sender docs. Also different clients seem to handle the results very differently. I'm looking for any insight into this particular problem, or best practices for getting this to work in *most* clients.

Thanks,
vroom

use Mail::Sender;            my $sender = new Mail::Sender            {smtp => 'smtp@blah.com', from => 'emailforyou@blah.com'};            if (ref $sender->OpenMultipart({            from => 'webmaster@ci.grand-rapids.mi.us', to => $to,            subject => 'mail message',            boundary => 'boundary-test-1',            multipart => 'related'})) {            $sender->Attach(            {description => 'html body',            ctype => 'text/html; charset=us-ascii',            encoding => '7bit',            disposition => 'NONE',            file => 'file.html'            });            $sender->Attach({            description => 'file1.jpg',            ctype => 'image/gif',            encoding => 'base64',            disposition => "inline; filename=\"file1.jpg\";\r\nContent-ID: <img1>"            +,            file => 'file1.jpg'            });            $sender->Attach({            description => 'logo.gif',            ctype => 'image/gif',            encoding => 'base64',            disposition => "inline; filename=\"logo.gif\";\r\nContent-ID: <img2>",            file => 'logo.gif'            });            $sender->Close() or die "Close failed! $Mail::Sender::Error\n";            } else {            die "Cannot send mail: $Mail::Sender::Error\n";            }            

Update:It does in fact appear to be the Outlook Issue referenced in the KB article in jlongino suggested since the code was somewhat more succinct.

Comment on Sending Inline Images in e-mail with Mail::Sender (or getting them to print in Outlook)
Download Code
Re: Sending Inline Images in e-mail with Mail::Sender (or getting them to print in Outlook)
by bbfu (Curate) on Mar 04, 2003 at 03:11 UTC

    Well, a couple minor things. Firstly, you didn't include the HTML file you use (file.html), which can make a difference. The problem might lie there. Specifically, with the syntax of the src="cid:img" references.

    Also, you're manually embedding one header (Content-ID) within another. It should work the way you have it, but it is "more correct" to use the content_id parameter to Attach (see code below).

    And though I'm sure it doesn't make any difference to the problem, you're giving the wrong content-type for the jpeg ('image/gif' instead of 'image/jpeg').

    Here is your code, slightly modified and formatted, and the html file I used. It seems to work for me, though I don't actually have Outlook to test it with. As far as I can tell, this is "correct", though, so it should work the same with Outlook as with my email client (PocoMail). If this doesn't work with Outlook, then I can only assume the problem is with Outlook and printing inline images. Perhaps you could try it in another mail client to see if it's an Outlook-specific issue.

    Update: There is a Knowledge Base Article (#287768) about this issue. You should check that to see if it's the same problem.

    The code:

    #!/usr/bin/perl                            use warnings;                            use strict;                            use Mail::Sender;                            my $sender = new Mail::Sender                            {smtp => 'your-smtp-server', from => 'testing@example.com'};                            if (ref $sender->OpenMultipart({                            from      => 'testing@example.com',                            to        => $to,                            subject   => 'mail message',                            boundary  => 'boundary-test-1',                            multipart => 'related',                            })) {                            print "Attaching body...\n";                            $sender->Attach({                            description => 'html body',                            ctype       => 'text/html; charset=us-ascii',                            encoding    => '7bit',                            disposition => 'none',                            file        => 'file.html',                            });                            print "Attaching jpeg...\n";                            $sender->Attach({                            description => 'file1.jpg',                            ctype       => 'image/jpeg',                            encoding    => 'base64',                            disposition => 'inline; filename="file1.jpg";',                            content_id  => 'img1',                            file        => 'file1.jpg'                            });                            print "Attaching gif...\n";                            $sender->Attach({                            description => 'logo.gif',                            ctype       => 'image/gif',                            encoding    => 'base64',                            disposition => 'inline; filename="logo.gif";',                            content_id  => 'img2',                            file        => 'logo.gif'                            });                            print "Closing / Sending\n";                            $sender->Close() or die "Close failed! $Mail::Sender::Error\n";                            } else {                            die "Cannot send mail: $Mail::Sender::Error\n";                            }                            

    The file.html:

    <html>                            <body>                            <p>Inline image number 1 (jpeg): <img src="cid:img1">                            <p>Inline image number 2 (gif):  <img src="cid:img2">                            </body>                            </html>                            

    bbfu
    Black flowers blossum
    Fearless on my breath

[reply]
[d/l]
[select]
      i was trying the same thing, and typed your code in and i can't get any of the images in the outlook email. they seem to be files, in the body of the email. in ms express they show up fine. is there a setting in Outlook that i should set? thanks in advance!
[reply]
Re: Sending Inline Images in e-mail with Mail::Sender (or getting them to print in Outlook)
by jlongino (Parson) on Mar 04, 2003 at 04:04 UTC
    You might want to use MIME::Lite instead. Here is some code (that I also shamelessly lifted from the docs). It viewed and printed correctly using Outlook Express. I liked the module installation and 'feel' of the code better too:
    use strict;                                    use warnings;                                    use MIME::Lite;                                    my $msg = MIME::Lite->new(                                    To      =>'someone@somewhere.net',                                    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 => '/some/path/myimage.gif',                                    );                                    $msg->send();                                    
    Update: It also views/prints correctly under Mozilla 1.2.1

    --Jim

[reply]
[d/l]
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
使用Perl處理電子郵件的方法的演化
接口測試基礎(chǔ)——第3篇smtplib發(fā)送帶圖片的郵件
Python SMTP發(fā)送郵件
python如何發(fā)送聲情并茂的郵件內(nèi)容、附件?
python使用smtplib和MIMEText發(fā)送郵件
Nginx http模塊(十)
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服