Link to home
Start Free TrialLog in
Avatar of wheaten

asked on

Sending HTML table in email to outlook 2007 client using

I am using 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 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 = _
            <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>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> %>

        ds = Nothing

        Dim strMsgBody As String = ""
        Dim smtp As New SmtpClient("")

        '** Send Email ***
        mail.From = New MailAddress("")

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

    End Sub
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

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.

mail.Body = StatsTable


mail.HTMLBody = StatsTable
Avatar of wheaten


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
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.
Avatar of wheaten


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:
Avatar of wheaten

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of wheaten


Without adding the .ToString it will strip the HTML tags.