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.Configur ation")
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
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.Configur
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Worked perfectly! Thanks!
Dim MyApp = CreateObject("Outlook.Appl
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()