473,756 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Customizing the message body in Net::SMTP

2 New Member
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:

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
5 5301
numberwhun
3,509 Recognized Expert Moderator Specialist
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
971 Recognized Expert Contributor
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
Feb 18 '08 #3
jimhill10
2 New Member
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
971 Recognized Expert Contributor
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
971 Recognized Expert Contributor
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

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

Similar topics

0
3061
by: Almir | last post by:
I hate this Net::SMTP stuff, everything works fine but for the suject field. I see no way of having it show in an email when sent. Has anyone had this problem, can anyone explain why there are no documentations on smtp or better ones at least. I just need the subject field to show. $smtp = Net::SMTP->new('some.your.com'); $smtp->mail ($mailfrom); #the administrator's email goes here $smtp->to('mine@your.com');
2
13704
by: RandRace | last post by:
I'm having some problems with a little script i wrote using net::smtp. I originally wrote it in linux where it works perfectly. I tried to use it from windows the other day and it doesn't work. It connects to the server and prints the banner but will not send mail. Here is my script: use Net::SMTP; my $smtp = Net::SMTP->new('smtp.comcast.net') or die "Can't Open server"!";
0
1331
by: peterson | last post by:
I was trying to send asp.net-smtp mail of UTF-8 unicode international character contents. When I opened the mailbox contents was broken. I am using html format too. Am I missing something?
1
1823
by: neog | last post by:
I'm having a problem with Net::Smtp. Does the datasend() method have problems sending strings containing single quotes? Like I stored the string "Germany's biggest bank, hired" in a hash and it prints out fine when i retrieve the scalar value. But i do datasend($msg) and when i open the email I see something like "Germany's bigges! t bank, hired". These "!" are popping all over the place. Any thoughts would be greatly appreciated.
11
2723
by: ibiza | last post by:
Hi all, I am trying to use the System.Net.Mail class for the first time, with ASP.NET 2.0. I setup everything according to http://www.codeproject.com/aspnet/EasySMTP_package.asp, which gives me a working environment for sending mails. I am sure the code is correct, there are no errors and everything seems
4
2371
by: patrickinminneapolis | last post by:
Hi guys, I'm trying to write an emailer, but I can't manage to construct the object properly. Here's what I've got: #!/usr/local/bin/perl -w use Net::SMTP; $smtp = Net::SMTP->new('mailhost'); print $smtp->domain,"\n"; $ perl mailer.txt Can't call method "domain" on an undefined value at mailer.txt line 6.
13
6809
by: jcor | last post by:
Hi, I'm trying some code to send a mail with my script. This is it: #!/usr/bin/perl use Net::SMTP; my $smtp_server='62.193.245.15'; my $smtp = Net::SMTP->new($smtp_server) or die "Can't Open server\n"; $smtp->mail('joao.correia@tvn.pt'); $smtp->to('jcor@sapo.pt'); $smtp->auth("joao.correia@tvn.pt","*password*");
1
2695
by: wootmaster | last post by:
I'm writing a script that will run a few tests on a given mail server, it's meant to test to see if VRFY and EXPN is enabled or not. However, when I use "verify" to test to see if VRFY is enabled on the given host, if VRFY is disabled on the server the "verify" function will still return true/1. I used the Debug function to check, and it shows that VRFY is disabled on the mail server. Is there a reason or a way around this? snippet of...
5
7346
by: veralee | last post by:
I'm in dire need to use Net::SMTP. The server no longer uses "sendmail". I found an example of using Net::SMTP but I have to also include a user name and password for the server. The host provided that, and I discovered that the method call is, auth ( USERNAME, PASSWORD ). But I don't know where to put that call. The host isn't into Perl and I'm on my own about this. Could someone be so extremely kind as to show me a simple example of...
0
9455
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9271
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10031
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9869
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9838
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3354
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2665
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.