Link to home
Start Free TrialLog in
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
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.
Change

mail.Body = StatsTable

to

mail.HTMLBody = StatsTable
Avatar of wheaten
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
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

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

Link to home
membership
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

ASKER

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