coder coder - 10 days ago 8
Vb.net Question

Add HTML table to Outlook Body

I am trying to use

Outlook
to send mails and I need to add
HTML table
inside my
Outlook body
.

This is what I have done but it is trying to add the
HTMLtags
but not the
design
.

Dim body As String
objOutlook = CType(CreateObject("Outlook.Application"), Outlook.Application)
objEmail = objOutlook.CreateItem(Outlook.OlItemType.olMailItem)
Dim strb As New StringBuilder
strb.Append("<table width='600px' align='center' border='0' cellpadding='0' cellspacing='0' style='border-top:5px solid white;'")
strb.Append("<tr><td>S.No</td><td>AccountID</td><td>ChargeEntryControl</td><td>PaymentPostingControl</td></tr></table>")
body = "Hi,
body += strb.ToString

Answer

Here is the full code I used, and it displays the email as I believe you want.

    Dim body As String
    Dim objOutlook As Object
    Dim objEmail As Object
    objOutlook = CType(CreateObject("Outlook.Application"), Outlook.Application)
    objEmail = objOutlook.CreateItem(Outlook.OlItemType.olMailItem)
    Dim strb As New StringBuilder
    strb.Append("<table width='600px' align='center' border='0' cellpadding='0' cellspacing='0' style='border-top:5px solid white;'")
    strb.Append("<tr><td>S.No</td><td>AccountID</td><td>ChargeEntryControl</td><td>PaymentPostingControl</td></tr></table>")
    body = "Hi,"
    body += strb.ToString
    objEmail.htmlbody = body
    objEmail.display()