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

Guys, I am trying to use MIME::Lite to send email attachments. My prob is that the content of my attachments get printed INSIDE the email text, when they shouldnt be. Any suggestions on how I can keep them separated? Thanks..Robert PS. Here is my code:
#!/usr/local/bin/perl use MIME::Lite; my $str; ### Create a new multipart message: $msg = MIME::Lite->new( From =>'robert@idi.net', To =>'robert@idi.net', Cc =>'some@other.com, some@more.com', subject =>'Here is an GIF and a text file attachment for you, cour +tesy of MIME::Lite', # Tried all the multipart types... Type =>'multipart/digest', #Type =>'text/plain', Data =>'Included with this email is a text file and a gif.', ); ### Add parts (each "attach" has same arguments as "new") $msg->attach(Type =>'image/gif', Path =>'/home/robert/newsroom.gif', Encoding => "base64", Filename =>'newsroom.gif' ); $msg->attach(Type =>'text/html', Path =>'/home/robert/attachme.txt', Filename =>'attachme.txt' ); $msg->send("smtp");

Replies are listed 'Best First'.
Re: How to separate attachments from the email body
by extremely (Priest) on Feb 08, 2001 at 03:28 UTC

    With the MIME::Tools package, I use MIME::Entity like the attached code. You should be using "multipart/mixed" unless you know why you aren't. You might want to add Disposition=>"attachment" to the HTML part and the gif parts. Some mailers will assume that the HTML is an alternative form of the text if you don't mark it as an attachment and other mailers will inline the gif at the end of your text if you don't mark it the same.

    MIME::Lite is a sister product and supports the same tricks. Add the Disposition and see...

    # my $mailer = MIME::Entity->build( From=>'Automated Mailer <you@test. +test>', my $mailer = MIME::Lite->new( From=>'Automated Mailer <you@test.test>' +, Subject=>"Report", To=>$email, Type=>"multipart/mixed", ); $mailer->attach(Type =>'image/gif', Path =>'/home/robert/newsroom.gif', Encoding => "base64", Filename =>'newsroom.gif', Disposition =>'attachment' ); $mailer->attach(Type =>'text/html', Path =>'/home/robert/attachme.txt', Filename =>'attachme.txt', Disposition =>'attachment' ); $mailer->smtpsend(Host=>'smtp.test.test', To=>$email);

    --
    $you = new YOU;
    honk() if $you->love(perl)

(jeffa) Re: How to separate attachments from the email body
by jeffa (Bishop) on Feb 08, 2001 at 01:45 UTC
    I tried this code and sent the first email to my Yahoo account. The result was similar: the attachments were part of the body message - even worse, the text file I sent was parsed into HTML.

    Next I sent an email to my Linux box and viewed it in (please don't laugh at me) PINE. The attachments were not part of the body - I could download them seperately.

    So, I believe that MIME::Lite is working correctly as specified, and the problem lies within the receiving mail transfer agent or maybe the mail delivery agent that puts the email in the user's mailbox. I am not an email expert, but sounds like the problem is out of your hands.

    Jeff

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    F--F--F--F--F--F--F--F--
    (the triplet paradiddle)
    
Re: How to separate attachments from the email body
by Adam (Vicar) on Feb 08, 2001 at 02:24 UTC
    I've played with MIME::Lite plenty of times, and your usage looks correct to me. I trust that jeffa's tests were sufficient, I just wanted to re-assure you that you are using the module correctly. jeffa is probably right, the problem is probably your mail reader.