Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 595
  • Last Modified:

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
0
sharpapproach
Asked:
sharpapproach
1 Solution
 
djon2003Commented:
The HTMLBody parameter accepts the HTML itself, not a file path. So you have to read the file and assign the content to HTMLBody.

As :
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(sHTMLPath, ForReading)

Dim html
html = objFile.ReadAll
objFile.Close

Open in new window


Now you can use the html string variable.
0
 
Bryan ButlerCommented:
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()
0
 
sharpapproachAuthor Commented:
Worked perfectly!  Thanks!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now