By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,997 Members | 1,470 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,997 IT Pros & Developers. It's quick & easy.

Customizing the message body in Net::SMTP

P: 2
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($POSTvalues) 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:

Expand|Select|Wrap|Line Numbers
  1. $smtp->mail( $from_email );
  2.         $smtp->to( $EmailRecipient, { SkipBad => 1 } );
  3.  
  4.         #~ $smtp->reset();
  5.  
  6.         $smtp->data();
  7.         $smtp->datasend('To: ');
  8.         $smtp->datasend( $EmailRecipient );
  9.         $smtp->datasend("\n");
  10.         $smtp->datasend("Subject: GTS Web Inquiry in MTI Format\n");
  11.         $smtp->datasend("MIME-Version: 1.0\n");
  12.         $smtp->datasend('Content-Type: multipart/mixed; boundary="--
  13.  
  14. =_NextPart_000_0018_01C0EA94.CF948390"' . "\n");
  15.         $smtp->datasend("\n");
  16.         $smtp->datasend("\n");
  17.         $smtp->datasend("This is a multi-part message in MIME format.\n");
  18.         $smtp->datasend("\n");
  19.         $smtp->datasend("----=_NextPart_000_0018_01C0EA94.CF948390\n");
  20.         $smtp->datasend("Content-Type: text/plain\n");
  21.         $smtp->datasend("Content-Transfer-Encoding: 7bit\n");
  22.         $smtp->datasend("\n");
  23.         $smtp->datasend("Import the attachment into Maximizer.\n");
  24.         $smtp->datasend("\n");
  25.         $smtp->datasend("----=_NextPart_000_0018_01C0EA94.CF948390\n");
  26.         $smtp->datasend('Content-Type: application/octet-stream; name="'. $attachfilename .'"' . 
  27.  
  28. "\n");
  29.         $smtp->datasend("Content-Transfer-Encoding: base64\n");
  30.         $smtp->datasend("Content-Disposition: attachment; filename=" . $attachfilename . "\n");
  31.         $smtp->datasend("\n");
  32.         $smtp->datasend( $mtifile );
  33.         $smtp->datasend("\n");
  34.         $smtp->datasend("\n");
  35.         $smtp->datasend("----=_NextPart_000_0018_01C0EA94.CF948390--\n");
  36.         $smtp->dataend();
  37.  
Here is what a selected portion of the html code looks like that is posted:

Expand|Select|Wrap|Line Numbers
  1. <INPUT TYPE="hidden" name="field_label_U_Gender_List" value="Seminary\Gender_List">
  2.                     <INPUT TYPE="hidden" name="field_name_U_Gender_List" value="Seminary\Gender_List">
  3.                     <INPUT TYPE="hidden" name="field_required_U_Gender_List" value="1">
  4.                     <INPUT TYPE="hidden" name="field_maxlength_U_Gender_List" value="1">
  5.                     <INPUT TYPE="hidden" name="field_type_U_Gender_List" value="0">
  6. <SELECT name="field_data_U_Gender_List" size="1" >
  7. <OPTION>Female</OPTION>
  8. <OPTION>Male</OPTION>
  9. </SELECT>
  10.  
Thanks!

Jim
Feb 18 '08 #1
Share this Question
Share on Google+
5 Replies


numberwhun
Expert Mod 2.5K+
P: 3,503
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
Feb 18 '08 #2

eWish
Expert 100+
P: 971
If you are using the CGI.pm you can use the param('field_name') method to retrieve them. Then simply place them in your message where you want them to appear.

--Kevin
Feb 18 '08 #3

P: 2
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:
Expand|Select|Wrap|Line Numbers
  1. $mtifile = encode_base64( $mtifile );
  2.  
  3.     my $smtp = Net::SMTP->new( $smtpserver, Timeout => 30 );
  4.  
  5.  
  6.  
  7.     foreach my $EmailRecipient ( @Emails )
  8.     {
  9.         $smtp->mail( $from_email );
  10.         $smtp->to( $EmailRecipient, { SkipBad => 1 } );
  11.  
  12.         #~ $smtp->reset();
  13.         # JMH Take the word Test out of the subject field when finished
  14.         $smtp->data();
  15.         $smtp->datasend('To: ');
  16.         $smtp->datasend( $EmailRecipient );
  17.         $smtp->datasend("\n");
  18.         $smtp->datasend("Subject: Test - GTS Web Inquiry in MTI Format\n");
  19.         $smtp->datasend("MIME-Version: 1.0\n");
  20.         $smtp->datasend('Content-Type: multipart/mixed; boundary="--=_NextPart_000_0018_01C0EA94.CF948390"' . "\n");
  21.         $smtp->datasend("\n");
  22.         $smtp->datasend("\n");
  23.         $smtp->datasend("This is a multi-part message in MIME format.\n");
  24.         $smtp->datasend("\n");
  25.         $smtp->datasend("----=_NextPart_000_0018_01C0EA94.CF948390\n");
  26.         $smtp->datasend("Content-Type: text/plain\n");
  27.         $smtp->datasend("Content-Transfer-Encoding: 7bit\n");
  28.         $smtp->datasend("\n");
  29.         $smtp->datasend("Import the attachment into Maximizer.\n");
  30.         $smtp->datasend("\n");
  31.         $smtp->datasend("----=_NextPart_000_0018_01C0EA94.CF948390\n");
  32.         $smtp->datasend('Content-Type: application/octet-stream; name="'. $attachfilename .'"' . "\n");
  33.         $smtp->datasend("Content-Transfer-Encoding: base64\n");
  34.         $smtp->datasend("Content-Disposition: attachment; filename=" . $attachfilename . "\n");
  35.         $smtp->datasend("\n");
  36.         $smtp->datasend( $mtifile );
  37.         $smtp->datasend("\n");
  38.         $smtp->datasend("\n");
  39.         $smtp->datasend("----=_NextPart_000_0018_01C0EA94.CF948390--\n");
  40.         $smtp->dataend();
  41.  
  42.         $smtp->quit;
  43.         $smtp = Net::SMTP->new( $smtpserver, Timeout => 30 );
Here is what a piece of my html form looks like with one sample field (there are a dozen):

Expand|Select|Wrap|Line Numbers
  1. <INPUT TYPE="hidden" name="field_label_U_Gender_List" value="Seminary\Gender_List">
  2.                     <INPUT TYPE="hidden" name="field_name_U_Gender_List" value="Seminary\Gender_List">
  3.                     <INPUT TYPE="hidden" name="field_required_U_Gender_List" value="1">
  4.                     <INPUT TYPE="hidden" name="field_maxlength_U_Gender_List" value="1">
  5.                     <INPUT TYPE="hidden" name="field_type_U_Gender_List" value="0">
  6. <SELECT name="field_data_U_Gender_List" size="1" >
  7. <OPTION>Female</OPTION>
  8. <OPTION>Male</OPTION>
  9. </SELECT>
Thanks in advance.
Feb 19 '08 #4

eWish
Expert 100+
P: 971
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 [CODE][/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
Feb 19 '08 #5

eWish
Expert 100+
P: 971
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
Feb 19 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.