ASP Classic CDOSYS Email via HTMLBody format - asp-classic

I have an issue sending an email using CDOSYS messaging system in ASP Classic using HTMLBody format. It seems to have a character limit, and when the email message is being sent, it cuts the message off around the bottom of the email. At first, I thought the message was being sent before the entire email could be written, but then after some troubleshooting and research, there is some sort of CDOSys message character limit when using HTMLBody. My question is, is there any way to override the character limit or get around the restriction? This is only for HTMLBODY.
EDIT: The "duplicate" flag would not have helped me. This is not a truncation issue, but an issue with HTMLBody limitations that prevent lengthy messages from fully being sent in the message. I checked that article and it was not what I was looking at an answer to. The responses on this thread were sufficient in answering my question. Thank you all.
Here is my code:
Set myMail=CreateObject("CDO.Message")
HTML = HTML & "<html>"
HTML = HTML & "<body>"
HTML = HTML & "<font face='calibri'>"
HTML = HTML & "<img src='http://" & SupportTagURLWebPath & "/images/SkypeEmailHeader.png'>"
HTML = HTML & "<br><Br>"
HTML = HTML & "<font face='calibri'>"
HTML = HTML & "<b>To " & Request.Form("SkypeTemplateName") & ":</b>"
HTML = HTML & "<br><br>"
HTML = HTML & "Thank you for contacting the Bank of America Service Desk. We're committed to providing seamless support in the moments that matter."
HTML = HTML & "<br><br>"
HTML = HTML & "We heard your concerns with Skype for Business audio/video, and recommend using approved Skype for Business devices to resolve the issue."
HTML = HTML & "<br><br>"
HTML = HTML & "<h4><font color='red'>What do I need to do?</font></h4>"
HTML = HTML & "<div style='background-color: #FFF8DC;'>"
HTML = HTML & "1. Visit the <a href='http://u.go/pchk'>Skype for Business Peripheral Checker</a> & complete the form.<br>"
HTML = HTML & "<img src='http://" &SupportTagURLWebPath & "/images/SkypeEmailbody.png'><br>"
HTML = HTML & "4. Once approved, your new device(s) will be shipped to you. To get started, visit the <a href='http://u.go/tIxvB5'>Skype for Business page</a> and select <i>Setup your equipment</i> tab."
HTML = HTML & "</div>"
HTML = HTML & "<br><br>"
HTML = HTML & "<br>"
HTML = HTML & "If you still encounter Skype for Business audio/visual issues with your new device(s), please <a href='http://u.go/7I76vm'>submit a web ticket</a> and one of our expert Bank of America Service Desk employees will reach out to you."
HTML = HTML & "Thank you,"
HTML = HTML & "<br>"
HTML = HTML & "Premium Service Desk"
HTML = HTML & "<br><Br>"
HTML = HTML & "<img src='http://" & SupportTagURLWebPath & "/images/SkypeEmailFooter.png'>"
HTML = HTML & "</font>"
HTML = HTML & "</body>"
HTML = HTML & "</html>"
myMail.Subject= "Skype for Business audio/visual experience"
myMail.From=EMAILADDRESS
myMail.To=Request.Form("SkypeTemplateEmail")
'mymail.CC= Request.Form("displayemail")
myMail.BCC="psd.wmwhc#bao.com"
myMail.ReplyTo="Do Not Reply"
'myMail.TextBody="This is a message."
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")="amta3dns.bo.com"
'Server port
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
myMail.Configuration.Fields.Update
'myMail.TextBody= Request.Form("genfeedback")
myMail.HTMLBody=HTML
myMail.Send
set myMail=nothing

It is a line length issue. Without the crlf you blow out the max length at 998 characters. Best thing to do would be to write a function that splits the content in mid-string, avoiding the html tags. HTML text, e.g. in a para, ignores line breaks.
The RFC says
There are two limits that this standard places on the number of
characters in a line. Each line of characters MUST be no more than
998 characters, and SHOULD be no more than 78 characters, excluding
the CRLF.
The 998 character limit is due to limitations in many implementations
which send, receive, or store Internet Message Format messages that
simply cannot handle more than 998 characters on a line. Receiving
implementations would do well to handle an arbitrarily large number
of characters in a line for robustness sake. However, there are so
many implementations which (in compliance with the transport
requirements of [RFC2821]) do not accept messages containing more
than 1000 character including the CR and LF per line, it is important
for implementations not to create such messages.
The more conservative 78 character recommendation is to accommodate
the many implementations of user interfaces that display these
messages which may truncate, or disastrously wrap, the display of
more than 78 characters per line, in spite of the fact that such
implementations are non-conformant to the intent of this
specification (and that of [RFC2821] if they actually cause
information to be lost). Again, even though this limitation is put on
messages, it is encumbant upon implementations which display messages
Thanks go to the blog at emailonacid for the pointer.

I was able to figure it out via another thread doing a google search. If you place the below line for every 3-5 lines of the email message, it seems to "reset" or loop the number limit back to the beginning without changing the format of the email. I am not sure if this is the correct way of handling it, but it seems to work for a number of messages I created today which have pretty lengthy messages that would otherwise be cut off when the message is sent. I hope this helps anyone else with this issue.
HTML = HTML & vbCrLf

Instead of inserting the message body in the script and using a lot of HTML = HTML & "text goes here", I created an actual HTML file and read each line in to the HTMLBody:
Set myFSO=Server.CreateObject("Scripting.FileSystemObject")
' Read Email Template File
Set myFile=myFSO.OpenTextFile(Server.MapPath("..\msg\"+Request.Form("Template")+".html"), 1)
EmailBodyTemplate=""
Do While myFile.AtEndOfStream=False
EmailBodyTemplate=EmailBodyTemplate&myFile.ReadLine
Loop
myFile.Close
Set myFile=Nothing
Set myFSO=Nothing
myMail.HTMLBody=EmailBodyTemplate
Not only will this automatically place a vbCrLf at the end of each line read in from the file but it also makes the function generic so that you can send any email you wish by changing the template name.

Related

Quote become " on PHPExcel

I'm using PHPExcel to export data into excel report. But the below characters are being altered.
" become "
& become &
Example:
"The Company" --> become "The Company"
Me & My Company --> become Me & My Company
Can anyone help me on how can I fix it. Thanks!!
Double-check the strings that you are passing to PHPExcel to make sure that they don't already have the HTML elements in them. Note that if you are debugging by dumping output to your browser then the string in your PHP code may actually already be
This & That
but the browser will display it as
This & That.

Using a variable from a VBScript in a ASP.Net website

I've been researching this for a majority of the day and can't find the answer. I am relatively new to stackoverflow. Is there a certain etiquette for asking a number of questions (I've asked three in the last few days)?
Anyways,
Here is the code in a codebehind file. It executes a script systeminfo.vbs, and that is working fine. But in the script I have some variables assigned.
Dim WshShell = CreateObject("WScript.Shell")
WshShell.Run("wscript.exe c:\systeminfo.vbs")
vbscript
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSettings = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colSettings
dim osName
osName = objOperatingSystem.Name
Wscript.Echo "OS Name: " & objOperatingSystem.Name
dim osVer
osVer = objOperatingSystem.Version
Wscript.Echo "Version: " & objOperatingSystem.Version
Wscript.Echo "Service Pack: " & _
objOperatingSystem.ServicePackMajorVersion _
& "." & objOperatingSystem.ServicePackMinorVersion
Wscript.Echo "OS Name: " & objOperatingSystem.SizeStoredInPagingFiles
Next
I want to use osName and osVer and put the values into a label on the ASP side.
I understand that osName and osVer are simple examples, but I just need to figure out the concept of putting variables from a VBScript into ASP. My client has multiple VBScripts they use on a daily basis and I need to automate those scripts and produce a report saying if it failed or not.
Thank you for the help.
David,
As a person new to Stack Overflow myself, I was happy to find this very comprehensive FAQ for Stack Exchange sites. See the 3rd question "Is there a limit on how many questions I can ask?" for an answer to your first inquiry.
Regarding the heart of your question, I agree with #Ramhound that using a log file to exchange information between your WSH/VBScript script and your ASP.NET page is a feasible approach.
What you need is the Scripting.FileSystemObject. Here is a comprehensive WSH reference as a downloadable Windows help file.
Hint: as the download page advises at the bottom, to unblock the help page, 1) Right click on script56.chm, 2) Choose Properties, and 3) Click on "Unblock."
You'll find an intro to FileSystemObject under the heading "Script Runtime."
One more suggestion: since you'll be running this script via ASP.NET in a multi-user environment, you may find you'll need to create a log file per user or per page access. If that is the case, you'll need to generate a temporary file name for each log file to avoid name collisions with other log files. To generate your temporary file, see GetTempName in the WSH reference.

Server side call to webservice in classic ASP

I've .NET webservice, which takes a encoded html-string as a parameter, decodes the string and creates a PDF from the html. I want to make a synchronous server side call to the webservice from a classic asp webpage. It works fine if use a plain text string (with no html tags), but when I send a encoded html string the webservice it seems that the string is empty when it reaches the webservice.
The webservice is working fine when I call it from client side, with both plain text string and an encoded html string.
My code looks like this:
Private Sub SaveBookHtmlToPdf(pHtml, pShopId)
Set oXMLHTTP = CreateObject("Msxml2.ServerXMLHTTP.6.0")
Dim strEnvelope
strEnvelope = "pShopId=" & pShopId & "&pEncodedHtml=" & Server.HTMLEncode(pHtml)
Call oXMLHTTP.Open("POST", "https://mydomain.dk:4430/PdfWebservice.asmx/SaveBookToPdf", false)
Call oXMLHTTP.SetRequestHeader("Content-Type","application/x-www-form-urlencoded")
Call oXMLHTTP.Send(strEnvelope)
Set oXMLHTTP = Nothing
End Sub
It smells like some kind of security issue on the server. It's working when posting a asynchronous call from the client side, but not when it comes from server side - it seems that the encoded html string is somehow not allowed in a server side call to the webservice.
Anyone who know how to solve this tricky problem?
This looks all wrong to me:
Server.HTMLEncode(pHtml)
Its quite common for developers to get confused between HTML encoding and URL encoding even though they are quite different. You are posting data that needs to be URL encoded. Hence your code should use URLEncode instead:
strEnvelope = "pShopId=" & pShopId & "&pEncodedHtml=" & Server.URLEncode(pHtml)
Edit:
One thing that URLEncode does that may not be compatible with a URLEncoded post is it converts space to "+" instead of "%20". Hence a more robust approach might be:
strEnvelope = "pShopId=" & pShopId & "&pEncodedHtml=" & Replace(Server.URLEncode(pHtml), "+", "%20")
Another issue to watch out for is that the current value of Response.CodePage will influence how the URLEncode encodes non-ASCII characters. Typically .NET does things by default in UTF-8. Hence you will also want to make sure that your Response.CodePage is set to 65001.
Response.CodePage = 65001
strEnvelope = "pShopId=" & pShopId & "&pEncodedHtml=" & Replace(Server.URLEncode(pHtml), "+", "%20")
This may or may not help but I use a handy SOAP Class for Classic ASP which solved a few problems I was having doing it manually. Your code would be something like this:
Set cSOAP = new SOAP
cSOAP.SOAP_StartRequest "https://mydomain.dk:4430/PdfWebservice.asmx", "", "SaveBookToPdf"
cSOAP.SOAP_AddParameter "pShopId", pShopId
cSOAP.SOAP_AddParameter "pEncodedHtml", Server.HTMLEncode(pHtml)
cSOAP.SOAP_SendRequest
' result = cSOAP.SOAP_GetResult("result")
You will probably need to set your namespace for it to work ("" currently), and uncomment the 'on error resume next' lines from the class to show errors.
AnthonyWJones made the point about URL encoding and HTML encoding, and the original problem being experienced is likely a combine of the two, a race condition if you will. While is was considered answered, it partially wasn't, and hopefully this answers the cause of the effect.
So, as the message get HTMLEncoded, the html entities for the tags become such '<' = '<'.
And as you may know, in URLEncoding, &'s delimit parameters; thus the first part of this data strEnvelope = "pShopId=" & pShopId & "&pEncodedHtml=" & Server.HTMLEncode(pHtml) upto the "&pEncodedHtml" bit, is fine. But then "<HTML>..." is added as the message, with unencoded &'s...and the receiving server likely is delimiting on them and basically truncating "&pEncodedHtml=" as a null assign: "&pEncodedHtml=<HTML>... ." The delimiting would be done on all &'s found in the URL.
So, as far as the server is concerned, the data for parameter &pEncodedHtml was null, and following it were now several other parameters that were considered cruft, that it likely ignored, which just happened to actually be your message.
Hope this provides additional info on issues of its like, and how to correct.

reading text file lines into asp.net contentplaceholder

I am new to ASP.Net and am trying to set up some content pages to work with my master page.
I currently have the following text hardcoded into an asp:contentplaceholder and it works just fine. I want to read lines in from a text file to produce those headlines and retain the current formatting. I tried using the tag i need each line as a separate tag. Below is the code in the content place holder. Id like to have this done in the Page_Load or the pre Init.
<p class="text1">--- We recently completed an evaluation for a large Ocean Tug fleet showing 70% particulate reduction, 11% NOx reduction and an 8% fuel economy improvement.</p>
<p class="text1">--- Our Product was added to the Grainger catalog as its primary emissions and fuel efficiency Catalyst.</p>
<p class="text1">--- Our Product is recommended by Mann-Hummel to promote better performance in Diesel Particulate Filters.</p>
The
IO.File.ReadAllLines()
method will read a text file and return to you an array of strings; one for each line of text.
You can then loop through that, building up the HTML string to place into the ContentPlaceHolder
Try the following:
Dim Lines() As String = IO.File.ReadAllLines(Path)
For Each f As String In Lines
Response.Write("<p class='text1'>" & f & "</p>")
Next
Edit: I noticed you want it inside a ContentPlaceHolder, therefore can't use Response.Write. If that's the case you can try using a Literal control and then append the previous code using LiteralName.Text &= f
Hopefully it helps!
Edit: Adding more code, supporting what #Brian M. has said:
Dim Content As String = String.Empty
Dim Lines() As String = IO.File.ReadAllLines(Path)
For Each TxtFromFile As String In Lines
Content &= "<p class='text1'>" & TxtFromFile & "<p>"
Next
Me.ContentPlaceHolder1.Controls.Add(New LiteralControl(Content))
I hope it helps.

Can you declare a variable in ASP classic like this?

I am trying to see if this can be done in classic ASP:
Dim myVar
myVar = <<< END
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>test</title>
</head>
<BODY>
END
I can do this in PHP, but I am not positivte if it can be done in ASP.
Problem is I need to handle the HTML output via a variable, and I don't want to go through the HTML and convert " to ""
EDIT:
I've found that this is called HEREDOC syntax in PHP.
Since its been asked, what I am trying to do is store HTML type tags (which may contain ', " characters which would otherwise break
myVar = "<stuff color="red">here</stuff>"
so I would need to fix it by replacing color="red" with color=""red""
PART OF THE PROBLEM:
I don't want to have to replace " with "" for the content as I assign it, I guess a HEREDOC syntax is not available for ASP classic.
OK FINE... :P
Since everyone is asking me WHY I am going about it this way, here is why, I have to support this old ASP code, I don't want to, but suddenly the scope of this old app changes that they want the contents (which used to be an HTML page) to be emailed, SO... I wanted to HEREDOC the HTML output, pass it to the mail function and have it email. Having said that, I know its sloppy, and I know it works better the other way, however this is what the job called for, I didn't want to re-write it, I just wanted to augment the output from HTML to HTML-EMAIL...
Hope that makes more sense ;)
The easiest thing to do would be to keep the HTML in a separate file, and then open that file using a TextStream object, reading the string into a variable.
No. One language's syntax isn't going to work in a different language. You can, however, assign a string literal to the variable:
Dim myVar
myVar = _
"<html xmlns=""http://www.w3.org/1999/xhtml"" lang=""en"" xml:lang=""en"">" & vbCrLf & _
"<head>" & vbCrLf & _
" <title>test</title>" & vbCrLf & _
"</head>" & vbCrLf & _
"" & vbCrLf & _
"<BODY>" & vbCrLf
I'm pretty sure you can't do exactly what you're asking here.
It might help, however, if you explained what you're trying to do. There may be some other way.
update:
You could consider putting your HTML fragments into seperate files. This would allow you to define them without having to do any reformatting of the HTML. In a similar manner you could put them into a database or even into resource files.
I'm still not 100% clear why you want these HTML fragments defined as variables, but these approaches would work.
there is no herodoc for asp :) gogo escape - its the only useable way

Resources