471,328 Members | 1,744 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,328 software developers and data experts.

Create an html e-mail using asp.net

I am using stringbuilder to create a html email message that is basically a
two column table with the field name in one column, and the field value in
another, and about 30 rows. I don't get any errors when the code runs, but
there seems to be always one field that has the wrong background color, or
has a "!" in the text of the e-mail message. On the e-mail message, when I
click "View Source", I see that at the end of many rows, there is a "!"
character at the end. So, instead of bgcolor="#b0e0e6", I see bgcolor="#b!
and then you have go down one line and all the way to the left (in view
source), to see the rest of the characters; 0e0e6". The location of this
error is different in other e-mails and depends on how many fields I put in
the particular e-mail. If I create a really short e-mail, then I don't have
this problem. Has anyone encountered this? Any help would be appreciated.
Here is the example code;

Dim strMessage As New StringBuilder

strMessage.Append("<html>")
strMessage.Append("<body>")
strMessage.Append("<table width=""100%"" border=""1"" align=""center""
cellpadding=""2"" cellspacing=""1"">")

strMessage.Append("<tr>")
strMessage.Append("<td width=""40%""
bgcolor=""#b0e0e6""><strong><fontcolor=""#000099"" size=""2"">")
strMessage.Append("Project Number")
strMessage.Append("</strong></td>")
strMessage.Append("<td width=""60%""
bgcolor=""#b0e0e6""><strong><fontcolor=""#000099"" size=""2"">")
strMessage.Append(strProjnum)
strMessage.Append("</strong></td>")
strMessage.Append("</tr>")

strMessage.Append("<tr>")
strMessage.Append("<td width=""40%""
bgcolor=""#b0e0e6""><strong><fontcolor=""#000099"" size=""3"">")
strMessage.Append("Request Number")
strMessage.Append("</font></strong></td>")
strMessage.Append("<td width=""60%""
bgcolor=""#b0e0e6""><strong><fontcolor=""#000099"" size=""4"">")
strMessage.Append(strRequestnum)
strMessage.Append("</font></strong></td>")
strMessage.Append("</tr>")

strMessage.Append("</table>")
strMessage.Append("</body>")
strMessage.Append("</html>")

Dim newMail As New MailMessage

newMail.From = "hr******@jcpenney.com"
newMail.To ="au*****@jcpenney.com"

newMail.Subject = "Hardware Request Confirmation - New"
newMail.Body = strMessage.ToString
newMail.BodyFormat = MailFormat.Html

SmtpMail.SmtpServer = "mailserver.jcpenney.com"
SmtpMail.Send(newMail)

Jul 21 '05 #1
1 1762
The problem is your are sending the entire message as a single line and that
lines length is over the supported length of the server. You can either
break your lines manually using VBCRLF or you can use a 3rd party product
that will do it for you.

You could use the http://www.freesmtp.net component. Just turn on
quoted-printable encoding and it will wrap the lines for you.

i.e.

strMessage.Append("<html>" & vbcrlf)
strMessage.Append("<body>" & vbcrlf)

76 characters per line is a safe length to send at because that number is
supported by all servers.
"aur56" <au***@discussions.microsoft.com> wrote in message
news:88**********************************@microsof t.com...
I am using stringbuilder to create a html email message that is basically a
two column table with the field name in one column, and the field value in
another, and about 30 rows. I don't get any errors when the code runs,
but
there seems to be always one field that has the wrong background color, or
has a "!" in the text of the e-mail message. On the e-mail message, when
I
click "View Source", I see that at the end of many rows, there is a "!"
character at the end. So, instead of bgcolor="#b0e0e6", I see
bgcolor="#b!
and then you have go down one line and all the way to the left (in view
source), to see the rest of the characters; 0e0e6". The location of this
error is different in other e-mails and depends on how many fields I put
in
the particular e-mail. If I create a really short e-mail, then I don't
have
this problem. Has anyone encountered this? Any help would be
appreciated.
Here is the example code;

Dim strMessage As New StringBuilder

strMessage.Append("<html>")
strMessage.Append("<body>")
strMessage.Append("<table width=""100%"" border=""1"" align=""center""
cellpadding=""2"" cellspacing=""1"">")

strMessage.Append("<tr>")
strMessage.Append("<td width=""40%""
bgcolor=""#b0e0e6""><strong><fontcolor=""#000099"" size=""2"">")
strMessage.Append("Project Number")
strMessage.Append("</strong></td>")
strMessage.Append("<td width=""60%""
bgcolor=""#b0e0e6""><strong><fontcolor=""#000099"" size=""2"">")
strMessage.Append(strProjnum)
strMessage.Append("</strong></td>")
strMessage.Append("</tr>")

strMessage.Append("<tr>")
strMessage.Append("<td width=""40%""
bgcolor=""#b0e0e6""><strong><fontcolor=""#000099"" size=""3"">")
strMessage.Append("Request Number")
strMessage.Append("</font></strong></td>")
strMessage.Append("<td width=""60%""
bgcolor=""#b0e0e6""><strong><fontcolor=""#000099"" size=""4"">")
strMessage.Append(strRequestnum)
strMessage.Append("</font></strong></td>")
strMessage.Append("</tr>")

strMessage.Append("</table>")
strMessage.Append("</body>")
strMessage.Append("</html>")

Dim newMail As New MailMessage

newMail.From = "hr******@jcpenney.com"
newMail.To ="au*****@jcpenney.com"

newMail.Subject = "Hardware Request Confirmation - New"
newMail.Body = strMessage.ToString
newMail.BodyFormat = MailFormat.Html

SmtpMail.SmtpServer = "mailserver.jcpenney.com"
SmtpMail.Send(newMail)

Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Andrew V. Romero | last post: by
1 post views Thread by Jim, N2VX | last post: by
6 posts views Thread by Frank Wilson | last post: by
18 posts views Thread by Steven Bethard | last post: by
1 post views Thread by sebastian.janoschka | last post: by

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.