Search code examples
javascripthtmlperlcgiperl-module

How to send an html page as an attachment with email in Perl


I recently started programming I know how to send a mail in perl, but I am generating a Scrollable tables in HTML page and I need to send it as an attachment in Perl and I have no idea about it. Could anyone help me?
Edit: This question is different then How can I send an HTML email with Perl?, I am asking for send html page as an attachment rather then sending a html Email


Solution

  • Since you said you are already using MIME::Lite, they explicitly say how to do this in their documentation:

    $msg = MIME::Lite->new(
         To      =>'you@yourhost.com',
         Subject =>'HTML with in-line images!',
         Type    =>'multipart/related'
    );
    $msg->attach(
        Type => 'text/html',
        Data => qq{
            <body>
                Here's <i>my</i> image:
                <img src="cid:myimage.gif">
            </body>
        },
    );
    $msg->attach(
        Type => 'image/gif',
        Id   => 'myimage.gif',
        Path => '/path/to/somefile.gif',
    );
    $msg->send();
    

    However, as has been pointed out in the comments and on their documentation page. You should really use an alternative. Mail::Sendmail works fine and tells you how to do this in their documentation