chandanperl has asked for the wisdom of the Perl Monks concerning the following question:

Dear All, I want to send HTML email as inline msg and one or more attachments. It goes fine in other email client but in outlook my HTML inline msg comes as attachment. can anybody gives me valid reason why it is so? OR does anybody have different idea other than than below code ?
#!/usr/bin/perl use Mail::Sender; $sender = new Mail::Sender ######### MS Exchange SMTP server #################### {smtp => '', from => ''}; $recipients = ""; if (ref $sender->OpenMultipart({ from => '', to => $recipients, subject => 'chandan Embedded Image Test', boundary => 'boundary-test-1', multipart => 'related'})) { ##################### I have to send this part msg as inline ######### +############# $sender ->Attach( {description => 'html body', ctype => 'text/html; charset=us-ascii', #encoding => '7bit', disposition => 'inline', file => 'file2.html', }); ################### I have to send this part msg as Attachment ###### +############### $sender ->Attach( {description => 'html body', ctype => 'text/html; charset=us-ascii', #ctype => 'text/html', #encoding => '7bit', #disposition => 'inline', file => 'auth_sasl.pl', }); $sender->Close() or die "Close failed! $Mail::Sender:: +Error\n"; } else { die "Cannot send mail: $Mail::Sender::Error\n"; } exit;

Replies are listed 'Best First'.
Re: EMail problem in outlook
by james2vegas (Chaplain) on Aug 25, 2009 at 10:30 UTC
    What part of your code does not work? For attachments set disposition => 'attachment; filename=*' and for inline set disposition => 'inline; filename=*'. If you need to send a file as the message body, set disposition => 'NONE'. This is from the Mail::Sender documentation. Also for reference Content disposition Types

    Also note that you need to set a Content-ID on any resources you need to refer to in your body (like images), e.g.:
    disposition => "inline; filename => \"img.gif";\r\nContent-ID: <img>",
      Work off this if you still have no luck:
      use Mail::Sender; eval { Mail::Sender->new( {from => 'user@domain.local', smtp => 'mailserver.domain.local'}) ->OpenMultipart({ to => 'user@domain.remote', subject => 'Subject Here!', multipart => 'related', }) ->Part({ ctype => 'text/html', disposition => 'NONE', msg => <<'*END*'}) <html><body> This is where your HTML Page will be <img src="cid:img1"> </body></html> *END* ->Attach({ description => 'image descr', ctype => 'image/jpeg', encoding => 'base64', disposition => "inline; filename=*;\r\nContent-ID: <img1>", file => '/path/to/image.jpg' }) ->Close(); } or print "Error sending mail: $Mail::Sender::Error\n";
        Hey, I have changed your code accordingly but i am not able to send emails to any account
      #!/usr/bin/perl use Mail::Sender; $sender = new Mail::Sender ######### MS Exchange SMTP server #################### {smtp => '', from => ''}; $recipients = ""; if (ref $sender->OpenMultipart({ from => '', to => $recipients, subject => 'chandan Embedded Image Test', boundary => 'boundary-test-1', multipart => 'related'})) { ##################### I have to send this part msg as inline ######### +############# $sender ->Attach( {description => 'html body', ctype => 'text/html; charset=us-ascii', #encoding => '7bit', disposition => 'NONE', file => 'file2.html', }); ################### I have to send this part msg as Attachment ###### +############### $sender ->Attach( {description => 'html body', ctype => 'text/html; charset=us-ascii', #ctype => 'text/html', #encoding => '7bit', #disposition => 'inline', file => 'auth_sasl.pl', }); $sender->Close() or die "Close failed! $Mail::Sender:: +Error\n"; } else { die "Cannot send mail: $Mail::Sender::Error\n"; } exit;
Re: EMail problem in outlook
by Anonymous Monk on Aug 25, 2009 at 10:16 UTC
    can anybody gives me valid reason why it is so?

    Contact microsoft?

      When I am sending mail Linux box to outlook it goes fine but when I am sending mail via MS Exchange server it gives me this error. I am using Mime::Lite+Net::Smtp(or Mail::Sender)
        That wasn't quite what your original post said. There should be no difference. Both servers should send the mail as is, and neither should show the html mail as your message (because of the wrong disposition type) in Outlook.
Re: EMail problem in outlook
by tokpela (Chaplain) on Aug 25, 2009 at 19:44 UTC

    {smtp => '', from => ''};

    You haven't specified an SMTP server to use.