ASP, vbscript, CDO Email through AWS is truncated? - email

I am moving this classic ASP app to AWS and using AWS SES SMTP to send site emails (automated, post registration email).
So, the code below works but when the email arrives it is truncated (incomplete)?
Mail Function:
Function Sendmail(Sender, Subject, Recipient, Body)
dim myMail, strServer
strServer = Request.ServerVariables("server_name")
if strServer <> "localhost" then
Set myMail=Server.CreateObject("CDO.Message")
myMail.Subject=Subject
myMail.From=Sender
myMail.To=Recipient
myMail.HTMLBody=Body
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
'Name or IP of remote SMTP server
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver")="email-smtp.us-east-1.amazonaws.com"
'Server port
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=465
'requires authentication
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")=1
'username
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername")="a username"
'password
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword")="a password"
'startTLS
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl")=true
myMail.Configuration.Fields.Update
myMail.Send
set myMail=nothing
end if
End function
Mail Body
<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'><html lang='en'><head> <meta http-equiv='Content-Type' content='text/html; charset=windows-1258'> <meta name='viewport' content='width=device-width, initial-scale=1'> <meta http-equiv='X-UA-Compatible' content='IE=edge'> <meta name='format-detection' content='telephone=no'> <title>Title</title> <link rel='stylesheet' type='text/css' href='http://www.website.com/styles.css'> <link rel='stylesheet' type='text/css' href='http://www.website.com/responsive.css'></head><body style='margin:0; padding:0;' bgcolor='#F0F0F0' leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'><table border='0' width='100%' height='100%' cellpadding='0' cellspacing='0' bgcolor='#F0F0F0'><tr><td align='center' valign='top' bgcolor='#F0F0F0' style='background-color: #F0F0F0;'> <br/> <table border='0' width='600' cellpadding='0' cellspacing='0' class='container'><tr><td class='header' align='left'><img src='http://www.website.com/images/email/logo_small_en.png'/> </td></tr><tr> <td class='container-padding content' align='left' bgcolor='#FFFFFF'> <br/><div class='title'>Welcome to the site! </div><br/><div class='body-text'> <p>Welcome to the website<div class='hr'></div><br/><div class='subtitle'>Have fun!</div><br/> </td></tr><tr> <td class='container-padding footer-text' align='left'><br/>© 2016 <br/> <br/>You are receiving this email because you registered for the website. Please click here to <a href=''>unsubscribe</a>. <br/> </td></tr></table></td></tr></table></body></html>
Truncated always at the same spot?
<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'><html lang='en'><head> <meta http-equiv='Content-Type' content='text/html; charset=windows-1258'> <meta name='viewport' content='width=device-width, initial-scale=1'> <meta http-equiv='X-UA-Compatible' content='IE=edge'> <meta name='format-detection' content='telephone=no'> <title>Title</title> <link rel='stylesheet' type='text/css' href='http://www.website.com/styles.css'> <link rel='stylesheet' type='text/css' href='http://www.website.com/responsive.css'></head><body style='margin:0; padding:0;' bgcolor='#F0F0F0' leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'><table border='0' width='100%' height='100%' cellpadding='0' cellspacing='0' bgcolor='#F0F0F0'> <tr> <td align='center' valign='top' bgcolor='#F0F0F0' style='background-color: #F0F0F0;'> <br/> <table border='0' width='600' cellpadding='0' cellspacing='0' class='container'> <tr> <td class='he
I can't seem to track this down? Is the error in my function or the mail body? Is it an AWS limitation?
Thanks for your thoughts,

SMTP servers can throw a "Line too long" error when a line of the email exceeds some server-defined length. Since your message is always truncated at the same spot try inserting line breaks into your message body. I know AWS SES SMTP can return this error but I am unsure as to what the limit is. Here is a related conversation with a similar error and CDO for reference.

CDO uses 7bit for content transfer encoding by default, which does not truncate the long lines.
You don't need a user defined function but specify an appropriate content transfer encoding for the message body.
8bit, quoted-printable and base64 are standard transfer encodings will take care of the long lines.
'...
myMail.Configuration.Fields.Update
myMail.HTMLBodyPart.ContentTransferEncoding = "8bit"
myMail.Send
'...

Related

how to get the file sent in xml response in perl?

Using the LWP user agent I am sending the request and getting the response.
I will get the response in html format and a file attached in it.
eg:
`<html>
<head>
<title>Download Files</title>
<meta http-equiv=\'Content-Type\' content=\'text/html; charset=utf-8\'>
<link rel=\'stylesheet\' href=\'http://res.mytoday.com/css/main.css\' type=\'text/css\'>
<link rel=\'stylesheet\' href=\'http://res.mytoday.com/css/Menu.css\' type=\'text/css\'>
<link rel=\'stylesheet\' href=\'/statsdoc/freeze.css\' type=\'text/css\'>
</head>
<body>
<table border=1>
<tr class=\'rightTableData\'>
<th>No.</th>
<th>File Name</th>
<th>File Size</th>
</tr><tr class=\'rightTableData\'>
<td>1</td><td>
<a href=\'/dlr_download?file=/mnt/dell6/SRM_DATA/data/API_FILE /20160329/LSUZisbZahtHNeImZJm_1-1.csv.zip\'>1-1.csv.zip</a>
</td><td>487 bytes</td> </tr>
</table>
</br></br>
<center><a href=\'/dlr_download?file=/mnt/dell6/SRM_DATA/data/API_FILE/20160329/LSUZisbZahtHNeImZJm-csv.zip\'>Download all</a></center>
</body></html>`
From this response I need to get the file. Can anyone help me to get the file from response.
Use a parser to extract the information. I used XML::LibXML, but I had to remove the closing br tags that made the parser fail.
#!/usr/bin/perl
use warnings;
use strict;
my $html = '<html>
<head>
<title>Download Files</title>
<meta http-equiv=\'Content-Type\' content=\'text/html; charset=utf-8\'>
<link rel=\'stylesheet\' href=\'http://res.mytoday.com/css/main.css\' type=\'text/css\'>
<link rel=\'stylesheet\' href=\'http://res.mytoday.com/css/Menu.css\' type=\'text/css\'>
<link rel=\'stylesheet\' href=\'/statsdoc/freeze.css\' type=\'text/css\'>
</head>
<body>
<table border=1>
<tr class=\'rightTableData\'>
<th>No.</th>
<th>File Name</th>
<th>File Size</th>
</tr><tr class=\'rightTableData\'>
<td>1</td><td>
<a href=\'/dlr_download?file=/mnt/dell6/SRM_DATA/data/API_FILE /20160329/LSUZisbZahtHNeImZJm_1-1.csv.zip\'>1-1.csv.zip</a>
</td><td>487 bytes</td> </tr>
</table>
<!-- </br></br> I had to comment this out! -->
<center><a href=\'/dlr_download?file=/mnt/dell6/SRM_DATA/data/API_FILE/20160329/LSUZisbZahtHNeImZJm-csv.zip\'>Download all</a></center>
</body></html>';
use XML::LibXML;
my $dom = 'XML::LibXML'->load_html( string => $html );
print $dom->findvalue('/html/body/table/tr[2]/td[2]/a/#href');
You could also use the recover flag to parse invalid HTML:
my $dom = 'XML::LibXML'->load_html( string => $html, recover => 1 );

how to create "send email" button on your own google maps website

Hi everybody :) I have a problem. I would like to make it so that when I enter the address. Click on "Send Email" button to send me an email with "http: //" in the form of a link which opens after pressing the Navigator Maps. My code is here.
<?php
echo "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml' dir='ltr' lang='en-us' xml:lang='en-us'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<meta http-equiv='Content-Language' content='en-us' />
<link rel='icon' type='image/gif' href='http://www.nsc.ee/rssimg/favicon.png' />
<link rel='stylesheet' href='contact.css' type='text/css' />
<link rel='stylesheet' href='info.css' type='text/css' />
<script src='http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places'>
http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'></script>
<script src='js/jquery.geocomplete.js'></script>
<script>
$(function(){
$('#geocomplete').geocomplete({
map: '.map_canvas',
details: 'form ',
markerOptions: {
draggable: true
}
});
$('#geocomplete').bind('geocode:dragged', function(event, latLng){
$('input[name=lat]').val(latLng.lat());
$('input[name=lng]').val(latLng.lng());
$('#reset').show();
});
$('#reset').click(function(){
$('#geocomplete').geocomplete('resetMarker');
$('#reset').hide();
return false;
});
$('#find').click(function(){
$('#geocomplete').trigger('geocode');
}).click();
});
</script>
<script>";
echo"
<form>
<table border='0' bgcolor='#1c1a1a'>
<tr>
<td align='center'><input id='geocomplete' type='text' size='48px' placeholder='Palun sisestage aadress' value='' /><form>
<label><font color=#FFFFFF>Pikkus:</font></label>
<input name='lng' type='text' size='20px' value=''>
<label><font color=#FFFFFF>Laius:</font></label>
<input name='lat' type='text' size='20px' value=''>
<a id='reset' href='#' style='display:none;'></a>
</form></td></tr></table>
<table border='0' bgcolor='#1c1a1a'>
<tr>
<td align='center'><div class='map_canvas'></div></td></tr></table></p>
</form>";
?>

How to configure WAMP and Smtp server

I have spent a significant time looking for an answer, and tried every solution without success :/
Basically I want to use wamp server to create contact form that will be sent to my mail address.
I have wamp running but for the life of me I can't figure out why I wouldn't receive the mails, I either get the 404 page when submitting the form, or lately "Warning: mail(): SMTP server response: 553 sorry, that domain isn't in my list of allowed rcpthosts".
I am now looking for a solution that will at least send the form to my address, whether it's secured or not I just want to see an actual mail successfully sent.
Thanks !
edit: here is the code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> Contact Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="page-wrap">
<div id="contact-area">
<form method="post" action="contactengine.php">
<label for="Name">Name:</label>
<input type="text" name="Name" id="Name" />
<label for="Email">Email:</label>
<input type="text" name="Email" id="Email" />
<label for="Message">Message:</label><br />
<textarea name="Message" rows="20" cols="20" id="Message"> </textarea>
<input type="submit" name="submit" value="Submit" class="submit-button" />
</form>
<div style="clear: both;"></div>
</div>
</div>
</body>
</html>
--then the contact engine--
<?php
$EmailFrom = "myadress#mail.com";
$EmailTo = "myadress#mail.com";
$Subject = "Nice & Simple Contact Form by CSS-Tricks";
$Name = Trim(stripslashes($_POST['Name']));
$Tel = Trim(stripslashes($_POST['Tel']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
--then the thanks message--
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Strict//EN">
<head>
<title>A Nice & Simple Contact Form</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="page-wrap">
<img src="images/title.gif" alt="A Nice & Simple Contact Form" />
<p>By CSS-Tricks</p>
<br /><br />
<h1>Your message has been sent!</h1><br />
<p>Back to Contact Form</p>
</div>
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-68528-29";
urchinTracker();
</script>
</body>
</html>
Windows does not come with a Mail Server so just calling mail() will work as far as php is concerned but the mail goes nowhere.
You either need to install a mail server or use something like the PHPMailer library to allow you to send SMTP mails via something like Yahoo or Google.

Extracting Text in body that is not part of tag with HTML::TreeBuilder

I have some ugly html that is emailed to my program that looks like:
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
</head>
<body>
Saved search results.<br>
<br>
Name: 'Some splunk search' <br>
Query Terms: 'tag=foo NOT BAR=\"Boom\"' <br>
Link to results: <a href="https://foo/search/blahblahblah">
https://foo/search/blahblahblah</a>
<br>
<br>
<table border="1">
...snipped the rest for brevity.
I am able to pull the table elements out using HTML::TreeBuilder but can't figure out how to
pull the "Name:" an "Query Terms" from above out without resorting to other means.
A $root->dump of the above looks like:
<html> #0
<head> #0.0
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> #0.0.0
<body> #0.1
<p> #0.1.0 (IMPLICIT)
" Saved search results. "
<br /> #0.1.0.1
<br /> #0.1.0.2
" Name: 'Some splunk search' "
<br /> #0.1.0.4
" Query Terms: 'tag=foo NOT BAR=\"Boom\""
So is there a way to get the naked text between the #0.1.0.2 and #0.1.0.4
Thanks!
Todd
If there is a pattern to the text, it might be easier to use a combination of HTML parsing and regular expressions.
my $body_text = $body->as_text(skip_dels => 1);
my ($name) = ($body_text =~ m#Name: '([^']+)'#s);
my ($query_terms) = ($body_text =~ m#Query Terms: '([^']+)'#s);

Simple asp form

Trying to get a very simple classic asp form up and running on 123-reg.
123-reg provide a script to get this done but I have no idea how this script connects to the form I've made.
Here's my html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>
<body>
<form id="form" target="_blank" action="script.asp" method="post">
Name: <input name="Name" type="text" /><br />
Customer ID: <input name="Customer ID" type="text" /><br />
Email Address: <input name="Email" type="text" /><br />
Comments:<br />
<textarea name="Comments" rows=5 cols=50></textarea>
<input type="submit" value="Submit" />
<input type="reset" value="Clear" />
</form>
</body>
</html>
And this is the simple script:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Secure Mail (ASP)</title>
</head>
<body>
<div id="container" class="index" style="padding:10px">
<br />
<br />
<h2>Secure Mail (ASP)</h2>
<br />
<%
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'To get the script for work please set the following values:
'Set the credentials for your email account to send the email from
username="MYUSERNAME" 'Insert your email account username between the double quotes
password="MYPASSWORD" 'Insert your email account password between the double quotes
'Set the from and to email addresses
sendFrom = "admin#MYURL.co.uk" 'Insert the email address you wish to send from
sendTo = "MYEMAIL" 'Insert the email address to send to in here
'DO NOT CHANGE ANY SCRIPT CODE BELOW THIS LINE.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'This script demonstrates how to send an email using asmtp
'Create a CDO.Configuration object
Set objCdoCfg = Server.CreateObject("CDO.Configuration")
'Configure the settings needed to send an email
objCdoCfg.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="intmail.atlas.pipex.net"
objCdoCfg.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objCdoCfg.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objCdoCfg.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 0
objCdoCfg.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = username
objCdoCfg.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = password
objCdoCfg.Fields.Update
'Create the email that we are going to send
Set objCdoMessage = Server.CreateObject("CDO.Message")
Set objCdoMessage.Configuration = objCdoCfg
objCdoMessage.From = sendFrom
objCdoMessage.To = sendTo
objCdoMessage.Subject = "This is a test email."
'Add the email body text
objCdoMessage.TextBody = "Email sent using ASMTP from a ASP script."
On Error Resume Next
'Send the email
objCdoMessage.Send
'Check if an exception was thrown
If Err.Number <> 0 Then
'Response.Write "<FONT color=""Red"">Error: " & Err.Description & " (" & Err.Number & ")</FONT><br/>"
Else
Response.Write "<FONT color=""Green"">The email has been sent to " & sendTo & ".</FONT>"
End If
'Dispose of the objects after we have used them
Set objCdoMessage = Nothing
Set objCdoCfg = Nothing
Set FSO = nothing
Set TextStream = Nothing
%>
</div>
</body>
</html>
I know the script works as it sends the email, however none of the information included in the HTML form seems to be included.
Don't usually work with forms so any advice would be gratefully received.
Thanks,
Dan
Nowhere in the asp are you requesting the form data to include in your email.
For example, instead of this in your asp:
sendTo = "MYEMAIL" 'Insert the email address to send to in here
You should use the email from the form:
sendTo = Request.Form("Email") 'Insert the email address to send to in here
You may want to validate the email address first:
if isEmailValid(Request.Form("Email")) = true then
'#### Send your email
else
'#### Email was invalid, give the user an error
response.write "Invalid email address"
end if
Function isEmailValid(email)
Set regEx = New RegExp
regEx.Pattern = "^\w+([-+.]\w+)*#\w+([-.]\w+)*\.\w{2,}$"
isEmailValid = regEx.Test(trim(email))
End Function
To confirm, the request.form collection uses the name="" property of the HTML form.
i.e. to include the contents of your textarea:
'Add the email body text
objCdoMessage.TextBody = "The following comment was submitted via the feedback form:" & Request.Form("Comments")