一区二区三区日韩精品-日韩经典一区二区三区-五月激情综合丁香婷婷-欧美精品中文字幕专区

分享

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

 sttx 2008-11-21

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 bbfu's post below. I ended up using Mime::Lite as 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ǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多

    亚洲综合一区二区三区在线| 国产一区二区精品丝袜| 色婷婷中文字幕在线视频| 亚洲欧美日本视频一区二区| 大胆裸体写真一区二区| 偷拍美女洗澡免费视频| 欧美中文字幕一区在线| 欧美激情一区二区亚洲专区| 亚洲综合日韩精品欧美综合区| 欧美日韩精品久久第一页| 五月婷日韩中文字幕四虎| 蜜桃传媒视频麻豆第一区| 日韩女优视频国产一区| 九九热在线免费在线观看| 欧美日韩亚洲精品内裤| 国产精品免费自拍视频| 日本人妻中出在线观看| 日本深夜福利视频在线| 欧美精品一区二区三区白虎| 老富婆找帅哥按摩抠逼视频| 在线观看日韩欧美综合黄片| 欧美一级不卡视频在线观看| 国产日产欧美精品大秀| 91亚洲国产成人久久| 亚洲黄香蕉视频免费看| 一区二区三区免费公开| 日韩午夜老司机免费视频| 日韩一区二区三区高清在| 欧美一级内射一色桃子 | 日韩精品少妇人妻一区二区| 国产精品第一香蕉视频| 日本东京热视频一区二区三区| 日韩成人免费性生活视频| 富婆又大又白又丰满又紧又硬| 国产精品国产亚洲区久久| 日韩成人免费性生活视频| 少妇毛片一区二区三区| 日韩美女偷拍视频久久| 千仞雪下面好爽好紧好湿全文| 自拍偷拍一区二区三区| 日韩欧美在线看一卡一卡|