Avatar of wheaten
wheaten
 asked on

Sending HTML table in email to outlook 2007 client using vb.net

I am using vb.net 2008 and trying to pull data from an access database and output the results to an HTML table in email to clients using Outlook 2007.  I can pull the data and send it just fine, but it will not display in a table in Outlook - so all the data is just jammed together and not readable.  I am not a vb.net expert, so please be as explicit as possible in your answer or use an example.

Here is my sub routine that is creating the HTML and sending the email:


    Private Sub SendStats()

        Dim StatsTable = _
        <html>
            <table style="FONT-SIZE: 12px; FONT-FAMILY: arial" cellSpacing="0" cellPadding="0" width="600" border="1">
                <tr><th>Officer Name</th>
                    <th>Total Calls</th>
                    <th>In Person, In Bank</th>
                    <th>In Person, Outside Bank</th>
                    <th>Phone Call</th>
                    <th>Hot</th>
                    <th>Warm</th>
                    <th>Cold</th>
                    <th>Ice Cold</th>
                    <th>Center of Influence</th>
                    <th>Existing Customer</th>
                    <th>New Prospect</th>
                </tr><%= From Stats In ds.Tables("WeeklyStats").AsEnumerable _
                         Order By Stats("OfficerName") _
                         Select <tr><td><%= Stats("OfficerName") %></td>
                                    <td><%= Stats("Total Calls") %></td>
                                    <td><%= Stats("in person in bank") %></td>
                                    <td><%= Stats("in person outside bank") %></td>
                                    <td><%= Stats("phone call") %></td>
                                    <td><%= Stats("hot") %></td>
                                    <td><%= Stats("warm") %></td>
                                    <td><%= Stats("cold") %></td>
                                    <td><%= Stats("ice cold") %></td>
                                    <td><%= Stats("center of influence") %></td>
                                    <td><%= Stats("existing customer") %></td>
                                    <td><%= Stats("new prospect") %></td>
                                </tr> %>
            </table>
        </html>

        ds.Dispose()
        ds = Nothing


        Dim strMsgBody As String = ""
        Dim smtp As New SmtpClient("mail.domain.com")

        '** Send Email ***
        mail.From = New MailAddress("Stats@domain.com")
        mail.To.Clear()
        mail.To.Add("user@domain.com")

        'send the content
        mail.Subject = "Weekly Prospect Stats"
        mail.IsBodyHtml = True
        mail.Body = StatsTable
        smtp.Send(mail) 'send the message

    End Sub
Programming Languages-Other.NET ProgrammingOutlook

Avatar of undefined
Last Comment
wheaten

8/22/2022 - Mon
Dave Baldwin

The first thing is to get the source of the message as it is received.  See if your version of Outlook will let you do that.  Copy it to a text file, hide any details you don't want disclosed and post it here so we can see what's going on.
David Lee

Change

mail.Body = StatsTable

to

mail.HTMLBody = StatsTable
wheaten

ASKER
In response to DaveBaldwin, here is what Outlook shows when I select View Source on the message:

<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">Officer NameTotal CallsIn Person, In BankIn Person, Outside BankPhone CallHotWarmColdIce ColdCenter of InfluenceExisting CustomerNew ProspectTim Burton569301748622729Tom Jones2897121018244Ringo Starr43149202410182221Davy Jones21122Mark Walhburg111018356Sonny Bonol201064677128Bob Dylan8626253Steven Tyler22211Mick Jagger413413
Your help has saved me hundreds of hours of internet surfing.
fblack61
Dave Baldwin

None of your HTML is being included.  I think you need to include the HTML in quoted strings "This is a quoted string" for it to be included in your variable StatsTable.
wheaten

ASKER
In response to BlueDevilFan:

When I change to use mail.HTMLBody = StatsTable I get the following error:

'HTMLBody' is not a member of 'System.Net.Mail.MailMessage'

I am currently using the following Imports:
System.Net.Mail
System.IO
System.Data.OleDb
ASKER CERTIFIED SOLUTION
wheaten

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
wheaten

ASKER
Without adding the .ToString it will strip the HTML tags.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.