Create an html e-mail using asp.net

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • aur56

    #1

    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="#b0e0e 6", 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.Appe nd("<html>")
    strMessage.Appe nd("<body>")
    strMessage.Appe nd("<table width=""100%"" border=""1"" align=""center" "
    cellpadding=""2 "" cellspacing=""1 "">")

    strMessage.Appe nd("<tr>")
    strMessage.Appe nd("<td width=""40%""
    bgcolor=""#b0e0 e6""><strong><f ontcolor=""#000 099"" size=""2"">")
    strMessage.Appe nd("Project Number")
    strMessage.Appe nd("</strong></td>")
    strMessage.Appe nd("<td width=""60%""
    bgcolor=""#b0e0 e6""><strong><f ontcolor=""#000 099"" size=""2"">")
    strMessage.Appe nd(strProjnum)
    strMessage.Appe nd("</strong></td>")
    strMessage.Appe nd("</tr>")

    strMessage.Appe nd("<tr>")
    strMessage.Appe nd("<td width=""40%""
    bgcolor=""#b0e0 e6""><strong><f ontcolor=""#000 099"" size=""3"">")
    strMessage.Appe nd("Request Number")
    strMessage.Appe nd("</font></strong></td>")
    strMessage.Appe nd("<td width=""60%""
    bgcolor=""#b0e0 e6""><strong><f ontcolor=""#000 099"" size=""4"">")
    strMessage.Appe nd(strRequestnu m)
    strMessage.Appe nd("</font></strong></td>")
    strMessage.Appe nd("</tr>")

    strMessage.Appe nd("</table>")
    strMessage.Appe nd("</body>")
    strMessage.Appe nd("</html>")

    Dim newMail As New MailMessage

    newMail.From = "hrequest@jcpen ney.com"
    newMail.To ="auresti@jcpen ney.com"

    newMail.Subject = "Hardware Request Confirmation - New"
    newMail.Body = strMessage.ToSt ring
    newMail.BodyFor mat = MailFormat.Html

    SmtpMail.SmtpSe rver = "mailserver.jcp enney.com"
    SmtpMail.Send(n ewMail)



  • Bill

    #2
    Re: Create an html e-mail using asp.net

    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.Appe nd("<html>" & vbcrlf)
    strMessage.Appe nd("<body>" & vbcrlf)

    76 characters per line is a safe length to send at because that number is
    supported by all servers.


    "aur56" <aur56@discussi ons.microsoft.c om> wrote in message
    news:88CC4004-3119-44B4-A409-B9133355E650@mi crosoft.com...[color=blue]
    >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="#b0e0e 6", 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.Appe nd("<html>")
    > strMessage.Appe nd("<body>")
    > strMessage.Appe nd("<table width=""100%"" border=""1"" align=""center" "
    > cellpadding=""2 "" cellspacing=""1 "">")
    >
    > strMessage.Appe nd("<tr>")
    > strMessage.Appe nd("<td width=""40%""
    > bgcolor=""#b0e0 e6""><strong><f ontcolor=""#000 099"" size=""2"">")
    > strMessage.Appe nd("Project Number")
    > strMessage.Appe nd("</strong></td>")
    > strMessage.Appe nd("<td width=""60%""
    > bgcolor=""#b0e0 e6""><strong><f ontcolor=""#000 099"" size=""2"">")
    > strMessage.Appe nd(strProjnum)
    > strMessage.Appe nd("</strong></td>")
    > strMessage.Appe nd("</tr>")
    >
    > strMessage.Appe nd("<tr>")
    > strMessage.Appe nd("<td width=""40%""
    > bgcolor=""#b0e0 e6""><strong><f ontcolor=""#000 099"" size=""3"">")
    > strMessage.Appe nd("Request Number")
    > strMessage.Appe nd("</font></strong></td>")
    > strMessage.Appe nd("<td width=""60%""
    > bgcolor=""#b0e0 e6""><strong><f ontcolor=""#000 099"" size=""4"">")
    > strMessage.Appe nd(strRequestnu m)
    > strMessage.Appe nd("</font></strong></td>")
    > strMessage.Appe nd("</tr>")
    >
    > strMessage.Appe nd("</table>")
    > strMessage.Appe nd("</body>")
    > strMessage.Appe nd("</html>")
    >
    > Dim newMail As New MailMessage
    >
    > newMail.From = "hrequest@jcpen ney.com"
    > newMail.To ="auresti@jcpen ney.com"
    >
    > newMail.Subject = "Hardware Request Confirmation - New"
    > newMail.Body = strMessage.ToSt ring
    > newMail.BodyFor mat = MailFormat.Html
    >
    > SmtpMail.SmtpSe rver = "mailserver.jcp enney.com"
    > SmtpMail.Send(n ewMail)
    >
    >
    >[/color]


    Comment

    Working...