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

Hi, I am using the module Mail:SendMail to mail some report(which contains some HTML tags) in a script.By default the content type is text/plain.My requirement is that the HTML tags in the report should be interpreted by the mail client(Outlook).So I guess it has something to do with the content type.How can I specify the content type for an object of type Mail::SendMail.If there is somthing else that I should do for HTML report please write it here.TIA

Replies are listed 'Best First'.
Re: Mail::SendMail Content -type setting
by atemon (Chaplain) on Aug 26, 2007 at 19:13 UTC

    Hi,

    you can pass any SMTP headers as a key-value pair ( hash ) as given below, to Mail::Sendmail

    use Mail::Sendmail; %mail = ( To => 'you@there.com', From => 'me@here.com', Content-Type => 'text/html' Message => "This is a very short message" ); sendmail(%mail) or die $Mail::Sendmail::error; print "OK. Log says:\n", $Mail::Sendmail::log;
    If you want to send a mail with attachment, you can specify Content-Type as multipart/mime and boundary. You can also send headers like Content-Disposition, Content-Transfer-Encoding etc in the same way.

    Cheers !

    --VC



    There are three sides to any argument.....
    your side, my side and the right side.

      ya but I am working on an existing code (which was written by some DUD) and I can't afford the luxury of changing that code too much.I am presenting a similar code here,
      $sm = new SendMail('Server Name'); $sm->From('aa@bb.com'); $sm->To('xx@yy.com'); $sm->Subject('just kill me'); $str="<HTML><strong>This is mail body</strong></HTML>"; $sm->setMailBody($str); $sm->sendMail();
      Is there any way(any sub-routine) of specifying the content-type over here??? just like the mail body and from and to addresses
        I does not seem like you are using Mail::Sendmail as suggested above in this thread. The code you provided looks a lot like the synopsis for Net::DNS::Sendmail. From looking at the source code, it does not seem to support setting the Content-Type.
        --
        Andreas
Re: Mail::SendMail Content -type setting
by andreas1234567 (Vicar) on Aug 26, 2007 at 19:06 UTC
Re: Mail::SendMail Content -type setting
by narainhere (Monk) on Aug 27, 2007 at 11:31 UTC

    Thank you all, I was able to figure out a solution and I am happy now.

    The mental-block for last 24 hrs is cleared now.Thanks for your concern.
    I am actually on a hurry now, so I will post my solution in detail very soon.

    $$Nice day!!$$