Link to home
Start Free TrialLog in
Avatar of sharpapproach
sharpapproach

asked on

Send HTML Format with Email Object

We send automated emails from a server as items are processed.  I have everything working, except for the HTML issues.  We used to use text verbiage, but they now want them in HTML formats where the user saves a file and we just pass the path in.  When I try this, it just takes the path name as the HTML text.  Any help is greatly appreciated.

Public Function SendEmail(sTo As String, sFrom As String, sCC As String, sSubject As String, sBody As String, sHTMLPath As String)
    Dim Invoices As String
    Dim MAIL, CON
    Set MAIL = CreateObject("CDO.Message")
    Set CON = CreateObject("CDO.Configuration")
    CON.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "172.16.10.1"  'change to your outbound smtp server
    CON.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    CON.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    CON.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
    CON.Fields.Update
    Set MAIL.Configuration = CON
    MAIL.From = sFrom
    MAIL.To = sTo
    MAIL.CC = sCC
    MAIL.Subject = sSubject
    MAIL.HTMLBody = sHTMLPath
   
    MAIL.send
   
    Set MAIL = Nothing
    Set CON = Nothing

End Function
ASKER CERTIFIED SOLUTION
Avatar of djon2003
djon2003
Flag of Canada image

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
Or how about:

Dim MyApp = CreateObject("Outlook.Application")
Dim MyItem = MyApp.CreateItem(0) 'olMailItem
With MyItem
                .To = "email@email.net; dave@dave.com"
                .Subject = "Log File: " + strFilename
                .ReadReceiptRequested = False
                .HTMLBody = "Log file attached:" + xPath + "\" + strFilename + "<br>Last modified: " + objFile.DateLastModified + "<br><br> System Info: <br>"
End With

Dim myAttachments = MyItem.Attachments
myAttachments.Add(xPath + "\" + strFilename, 1, 1, "Read Me")
MyItem.Display()
Avatar of sharpapproach
sharpapproach

ASKER

Worked perfectly!  Thanks!