5

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 
jrp1982
  • 113
  • 2
  • 7
  • If you do a `Response.Write(Server.HTMLEncode(HTML))` before the `.Send`, do you see the whole message? – Flakes May 22 '17 at 13:42
  • Thanks for your response. I just tried this and it doesn't even get that far. Still gets cut off. – jrp1982 May 22 '17 at 17:27

3 Answers3

4

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.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Vanquished Wombat
  • 9,075
  • 5
  • 28
  • 67
  • Thanks for this info. This is definitely a better approach than adding vbCrLf every 3-5 lines which imo sloppy but worked. Ill give this a try and see how it pans out. Appreciate your assistance! – jrp1982 May 24 '17 at 11:08
2

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
jrp1982
  • 113
  • 2
  • 7
0

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.

Howard Parr
  • 119
  • 8
  • With the added caveat that you can open the HTML email template in your browser and see exactly how it is going to look. – Howard Parr Dec 16 '18 at 02:55
  • Further, by using placeholders in your HTML template file, like [FirstName], etc., you can easily customize the template using the following code: EmailBodyTemplate=Replace(EmailBodyTemplate,"[FirstName]",Request.Form("FirstName")) – Howard Parr Dec 16 '18 at 03:17