Customizing the message body in Net::SMTP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jimhill10
    New Member
    • Feb 2008
    • 2

    Customizing the message body in Net::SMTP

    I have a perl script that creates an email attachment file from POST data on a web page. This works just fine. I want to customize the email body to contain all of the text data from the file itself. I thought this would be just a matter of using the $smtp->datasend($POST values) with the $values coming from the names on the web page posting the data. Can someone show me what the correct code snippet would be? Here is my code:

    [code=perl]
    $smtp->mail( $from_email );
    $smtp->to( $EmailRecipient , { SkipBad => 1 } );

    #~ $smtp->reset();

    $smtp->data();
    $smtp->datasend('To : ');
    $smtp->datasend( $EmailRecipient );
    $smtp->datasend("\n") ;
    $smtp->datasend("Subj ect: GTS Web Inquiry in MTI Format\n");
    $smtp->datasend("MI ME-Version: 1.0\n");
    $smtp->datasend('Cont ent-Type: multipart/mixed; boundary="--

    =_NextPart_000_ 0018_01C0EA94.C F948390"' . "\n");
    $smtp->datasend("\n") ;
    $smtp->datasend("\n") ;
    $smtp->datasend("Th is is a multi-part message in MIME format.\n");
    $smtp->datasend("\n") ;
    $smtp->datasend("----=_NextPart_000_ 0018_01C0EA94.C F948390\n");
    $smtp->datasend("Cont ent-Type: text/plain\n");
    $smtp->datasend("Cont ent-Transfer-Encoding: 7bit\n");
    $smtp->datasend("\n") ;
    $smtp->datasend("Impo rt the attachment into Maximizer.\n");
    $smtp->datasend("\n") ;
    $smtp->datasend("----=_NextPart_000_ 0018_01C0EA94.C F948390\n");
    $smtp->datasend('Cont ent-Type: application/octet-stream; name="'. $attachfilename .'"' .

    "\n");
    $smtp->datasend("Cont ent-Transfer-Encoding: base64\n");
    $smtp->datasend("Cont ent-Disposition: attachment; filename=" . $attachfilename . "\n");
    $smtp->datasend("\n") ;
    $smtp->datasend( $mtifile );
    $smtp->datasend("\n") ;
    $smtp->datasend("\n") ;
    $smtp->datasend("----=_NextPart_000_ 0018_01C0EA94.C F948390--\n");
    $smtp->dataend();
    [/code]

    Here is what a selected portion of the html code looks like that is posted:

    [code=html]
    <INPUT TYPE="hidden" name="field_lab el_U_Gender_Lis t" value="Seminary \Gender_List">
    <INPUT TYPE="hidden" name="field_nam e_U_Gender_List " value="Seminary \Gender_List">
    <INPUT TYPE="hidden" name="field_req uired_U_Gender_ List" value="1">
    <INPUT TYPE="hidden" name="field_max length_U_Gender _List" value="1">
    <INPUT TYPE="hidden" name="field_typ e_U_Gender_List " value="0">
    <SELECT name="field_dat a_U_Gender_List " size="1" >
    <OPTION>Femal e</OPTION>
    <OPTION>Male</OPTION>
    </SELECT>
    [/code]

    Thanks!

    Jim
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    Jim,

    Please keep your questions in the Forum and not the Articles area. The Articles area is only for tutorial's and How To's.

    Regards,

    Moderator

    Comment

    • eWish
      Recognized Expert Contributor
      • Jul 2007
      • 973

      #3
      If you are using the CGI.pm you can use the param('field_na me') method to retrieve them. Then simply place them in your message where you want them to appear.

      --Kevin

      Comment

      • jimhill10
        New Member
        • Feb 2008
        • 2

        #4
        Customizing the message body in Net::SMTP

        I am customizing a pretty basic perl script which receives html POST data from a form, creates an sends an email attachment. This aspects works fine. I want to add the values from the POST data off the form into the message body. Kevin (this site admin) suggested that I use the param method. I can't get this to work, I am new to perl but not to unix programming.

        Here is my working .pl script less the customization:
        [CODE=perl]
        $mtifile = encode_base64( $mtifile );

        my $smtp = Net::SMTP->new( $smtpserver, Timeout => 30 );



        foreach my $EmailRecipient ( @Emails )
        {
        $smtp->mail( $from_email );
        $smtp->to( $EmailRecipient , { SkipBad => 1 } );

        #~ $smtp->reset();
        # JMH Take the word Test out of the subject field when finished
        $smtp->data();
        $smtp->datasend('To : ');
        $smtp->datasend( $EmailRecipient );
        $smtp->datasend("\n") ;
        $smtp->datasend("Subj ect: Test - GTS Web Inquiry in MTI Format\n");
        $smtp->datasend("MI ME-Version: 1.0\n");
        $smtp->datasend('Cont ent-Type: multipart/mixed; boundary="--=_NextPart_000_ 0018_01C0EA94.C F948390"' . "\n");
        $smtp->datasend("\n") ;
        $smtp->datasend("\n") ;
        $smtp->datasend("Th is is a multi-part message in MIME format.\n");
        $smtp->datasend("\n") ;
        $smtp->datasend("----=_NextPart_000_ 0018_01C0EA94.C F948390\n");
        $smtp->datasend("Cont ent-Type: text/plain\n");
        $smtp->datasend("Cont ent-Transfer-Encoding: 7bit\n");
        $smtp->datasend("\n") ;
        $smtp->datasend("Impo rt the attachment into Maximizer.\n");
        $smtp->datasend("\n") ;
        $smtp->datasend("----=_NextPart_000_ 0018_01C0EA94.C F948390\n");
        $smtp->datasend('Cont ent-Type: application/octet-stream; name="'. $attachfilename .'"' . "\n");
        $smtp->datasend("Cont ent-Transfer-Encoding: base64\n");
        $smtp->datasend("Cont ent-Disposition: attachment; filename=" . $attachfilename . "\n");
        $smtp->datasend("\n") ;
        $smtp->datasend( $mtifile );
        $smtp->datasend("\n") ;
        $smtp->datasend("\n") ;
        $smtp->datasend("----=_NextPart_000_ 0018_01C0EA94.C F948390--\n");
        $smtp->dataend();

        $smtp->quit;
        $smtp = Net::SMTP->new( $smtpserver, Timeout => 30 );[/CODE]

        Here is what a piece of my html form looks like with one sample field (there are a dozen):

        [CODE=perl]<INPUT TYPE="hidden" name="field_lab el_U_Gender_Lis t" value="Seminary \Gender_List">
        <INPUT TYPE="hidden" name="field_nam e_U_Gender_List " value="Seminary \Gender_List">
        <INPUT TYPE="hidden" name="field_req uired_U_Gender_ List" value="1">
        <INPUT TYPE="hidden" name="field_max length_U_Gender _List" value="1">
        <INPUT TYPE="hidden" name="field_typ e_U_Gender_List " value="0">
        <SELECT name="field_dat a_U_Gender_List " size="1" >
        <OPTION>Femal e</OPTION>
        <OPTION>Male</OPTION>
        </SELECT>[/CODE]

        Thanks in advance.
        Last edited by eWish; Feb 19 '08, 08:51 PM. Reason: Please use [CODE][/CODE] tags

        Comment

        • eWish
          Recognized Expert Contributor
          • Jul 2007
          • 973

          #5
          jimhill10,

          Please do not start a new thread when you already have a thread going regarding your issue. I have merged the two threads for you. Also, it is expected of you to use the &#91;CODE]&#91;/CODE] tag when posting code samples here at TSDN. I have fixed that for you as well. Please read the Posting Guidelines before making any additional posts.

          Thank You!

          Moderator

          Comment

          • eWish
            Recognized Expert Contributor
            • Jul 2007
            • 973

            #6
            This appears to be part of the Maximizer Content Management Software. With that being said, you should consult them for support of their product if that is the case here.

            --Kevin

            Comment

            Working...