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

Dear All, This code is only able to send email in outlook and yahoo, but it isn't working for thunderbird,gmail,hotmail. Please help
use Mail::Sender; eval { (new Mail::Sender) ->OpenMultipart({ to => 'someone@somewhere.com', subject => 'Alternatives with images', # debug => 'c:\temp\zkMailFlow.log', multipart => 'related', }) ->Part({ctype => 'multipart/alternative'}) ->Part({ ctype => 'text/plain', dispos +ition => 'NONE', msg => <<'*END*' }) A long mail message. *END* ->Part({ctype => 'text/html', disposit +ion => 'NONE', msg => <<'*END*'}) <html><body><h1>A long</h1><p align=center> mail message. <img src="cid:img1"> </p></body></html> *END* ->EndPart("multipart/alternative") ->Attach({ description => 'ed\'s jpg', ctype => 'image/jpeg', encoding => 'base64', disposition => "inline; filename=\"051 +8m_b.jpg\";\r\nContent-ID: <img1>", file => 'E:\pix\humor\0518m_b.jpg' }) ->Close(); } or print "Error sending mail: $Mail::Sender::Error\n";

Replies are listed 'Best First'.
Re: problem with Mail::Sender while sending email
by james2vegas (Chaplain) on Aug 26, 2009 at 04:44 UTC
    Ok, ignoring the fact you're posting a new question instead of on the old thread, and not using already working code I gave you as a base, there are a few problems here:
    • You don't have an smtp or from parameter in your new Mail::Sender call
    • Your heredocs are terminated with *END* but the *END* is not at the beginning of the line
    • Fixing those, the code does work when sending mail to Thunderbird and Outlook (I havent't tried the others)

    Update: Ok, the first two issues are resolved, but still, yes this code does successfully send inline html mail to outlook and thunderbird.
      Please check it. I have modified the code.
      #!/usr/bin/perl use Mail::Sender; open(FH,"file.txt"); my $var; while(<FH>) { $var .= $_; } close(FH); eval { Mail::Sender->new( {from => 'from@domain.com', smtp => 'smtp.server.com'}) ->OpenMultipart({ to => '', subject => 'Subject Here!', multipart => 'related', }) ->Part({ ctype => 'text/html', disposition => 'NONE', msg => <<'*END*' $var}) $var *END* ->Attach({ description => 'test file', ctype => 'application/octet-stream', encoding => 'base64', disposition => "attachment; filename= file1 ", file => 'file1' }) ->Close(); } or print "Error sending mail: $Mail::Sender::Error\n";
        Please check this code
        ->Part({ ctype => 'text/html', disposition => 'NONE', msg => <<'*END*'}) $var *END*
Re: problem with Mail::Sender while sending email
by chandanperl (Novice) on Aug 26, 2009 at 04:39 UTC
    I am using this code.The code which i posted earlier that was original code from doc.
    #!/usr/bin/perl use Mail::Sender; open(FH,"file.txt"); my $var; while(<FH>) { $var .= $_; } close(FH); eval { Mail::Sender->new( {from => '', smtp => ''}) ->OpenMultipart({ to => '', subject => 'Subject Here!', multipart => 'related', }) ->Part({ ctype => 'text/html', disposition => 'NONE', msg => $var}) ->Attach({ description => 'test file', ctype => 'application/octet-stream', encoding => 'base64', disposition => "attachment; filename= file1 ", file => 'file1' }) ->Close(); } or print "Error sending mail: $Mail::Sender::Error\n";