Monday, March 26, 2012

SMTP MailMessage Body Problem

Im sending an automated email in response to a website request. The body of the email is in HTML format. The body of the message gets a !%20 inserted into the HTML after about 989 characters interupting a very important link. When I view the source of the problem email the !%20 appears at the very end of the line where the source viewer forces the text string to begin on a new line. My guess is that there is a character limit in the body for a single line.

How do I break my HTML string up into several lines so that this random character does not get inserted? Is there a line feed or a carriage return I can plant in the text to indicate to the SMTP server that a new line of HTML code has started?

Here is a sample of my code...

Dim ObjMM As New MailMessage
ObjMM.From = "autoemail@dotnet.itags.org.my.web.com"
ObjMM.To = strEmail
ObjMM.Subject = "Here is your requested email."
ObjMM.Body = <lots and lots of html...>
ObjMM.BodyFormat = MailFormat.Html
SmtpMail.SmtpServer = my.smtp.server
SmtpMail.Send(ObjMM)http://mailformat.dan.info/body/linelength.html
That was a good source of info. It pointed me in the right direction, thanks. The simple answer is that I need to put the vbCRLF constant in my strings often enough that no one single line goes over 998 characters.

"<p>This is junk</p>" & vbCRLF & "<p>This is more junk</p>"

0 comments:

Post a Comment