By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,478 Members | 1,374 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,478 IT Pros & Developers. It's quick & easy.

Multipart alternative emails with attachment

P: 1
Hello all,
Thanks in advance for your help
I have a problem in sending emails, my requirement is to send multipart alternative emails with attachments, I'm able to send text with attachments or HTML mails with attachments, but some mail clients are not able to display the html mails that is why I need to send multipart alternative emails, when I used multipart/alternative then I'm not able to send attachments and if I use the multipart/mixed then I'm able to send the attachments but in this case both the HTML content and the text content are displayed in the email.

below is the code I'm using

#!/usr/bin/perl -w

use CGI qw /:standard center/;
use CGI::Carp qw(fatalsToBrowser);
use HTTP::Request::Common;
use LWP::UserAgent;
use MIME::Lite;

my $msg = MIME::Lite->new(
From => '"abc" <abc@abc.com>',
To => 'xyz@xyz.com',
Subject => 'MultiPart Alternative 1',
Type => 'multipart/Mixed'
);

$msg->attach(
Type => 'text/html',
Data => '<body><h1>Test mail message this is HTML message</h1></body>'
);

$msg->attach(
Type => 'text/plain',
Data => 'Test mail message this is text message'
);


$part = MIME::Lite->new(
Type =>'image/jpeg',
Path => 'filename.jpg',
Filename => 'filename.jpg'
);


### Attach it to any message:
$msg->attach($part);

$msg->send("smtp", "127.0.0.1", Timeout => 30);
here when I execute this code I'm able to send the attachment but both the text content and email content dipslyed in the mail.
and in plce of
my $msg = MIME::Lite->new(
From => '"abc" <abc@abc.com>',
To => 'xyz@xyz.com',
Subject => 'MultiPart Alternative 1',
Type => 'multipart/Mixed'
);
if I used
my $msg = MIME::Lite->new(
From => '"abc" <abc@abc.com>',
To => 'xyz@xyz.com',
Subject => 'MultiPart Alternative 1',
Type => 'multipart/Alternative'
);
then I'm not able to send the attachment.
Please if any one has the solution about this then let me know ASAP , its very urgent.
Thanks with regards
Jan 17 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.