
Originally Posted by
graviz
I've started reading about sending e-mail from Access and was wondering if anyone has a good tutorial for it. Here's a piece of code I found but would like the ability to further format it. I used to know html but I'm not sure how to use it in the code. Has anyone seen anything where it gives you the code and then shows you what it actually will look like in an e-mail?
Dim OL As Object, MailSendItem As Object
Dim cust, prog, mess
Set OL = CreateObject("Outlook.Application")
Set MailSendItem = OL.CreateItem(olMailItem)
With MailSendItem
.Subject = "Routing:" & "Please complete the Sales Block and Close"
.HTMLBody = .HTMLBody & "<body><font color=#ff0000>"
.HTMLBody = .HTMLBody & "<p>Customer: " & cust & "</p>"
.HTMLBody = .HTMLBody & "<p>Program: " & prog & "</p>"
.HTMLBody = .HTMLBody & "<p>Subject: " & mess & "</p>"
.HTMLBody = .HTMLBody & "<p>Please complete the First Sales Block and Close</p>"
.HTMLBody = .HTMLBody & "</font></body>"
.To = ""
.CC = ""
.Attachments.Add
.Importance = 2 ' olImportanceHigh
.Display
.Send
End With
Hey graviz:
From the response you have gotten, are you looking for how to format the HTML for the email, or how to send HTML emails from MS Access?
If you're wanting to send emails, and the user of the application has MS Outlook installed, here is a code example using a third party tool to bypass the internetal security issues within Outlook (Third Party tool is Outlook Redemption http://www.dimastr.com/redemption/) Developer Copy is free to download and use, Purchase price is $199 for unlimited users or projects.)
Here is an example that I currently use to send Text based email.
Code:
Dim Application As New Outlook.Application
Dim SafeItem As Redemption.SafeMailItem, oItem As Outlook.MailItem
Dim Utils As Redemption.MAPIUtils
Dim DC As Redemption.SafeCurrentUser, Tag As Variant
Set Utils = New Redemption.MAPIUtils
Set SafeItem = New Redemption.SafeMailItem
Set oItem = Application.CreateItem(olMailItem)
With SafeItem
.Item = oItem
Tag = SafeItem.GetIDsFromNames("{00020386-0000-0000-C000-000000000046}", "From")
Tag = Tag Or &H1E
.Fields(Tag) = "Current User Name <Username@DomainName.com>"
.Recipients.Add ("AdditionalUser@domainname.com")
.Recipients.ResolveAll
.Subject = "SUBJECT LINE GOES HERE"
.Subject = .Subject 'Must have this in order for Redemption to have the subject line
.Body = "Hey Team," & vbCrLf & vbCrLf & _
"The Batch " & BatchNumber & " is ready for Processing. " & vbCrLf & vbCrLf & _
"Files Imported: " & FileNumber & vbCrLf & _
"Images Imported: " & Images
.Save
.Send
End With
Utils.DeliverNow
Here is an example of how to send and HTML Email:
Code:
set Appt = Application.CreateItem(olMailItem)
set sItem = CreateObject("Redemption.SafeMailItem")
sItem.Item = Appt
sItem.Recipients.Add "user@domain.com"
sItem.Recipients.ResolveAll
sItem.Subject = "test subject"
sItem.HTMLBody = "<html><body><b>bold</b> text</body></html>"
PR_InetMailOverrideFormat = &H59020003
ENCODING_PREFERENCE = &H00020000
BODY_ENCODING_TEXT_AND_HTML = &H00100000
ENCODING_MIME = &H00040000
PR_MSG_EDITOR_FORMAT = &H59090003
EDITOR_FORMAT_PLAINTEXT = 1
EDITOR_FORMAT_HTML = 2
sItem.Fields(PR_InetMailOverrideFormat) = ENCODING_PREFERENCE or ENCODING_MIME or BODY_ENCODING_TEXT_AND_HTML
sItem.Fields(PR_MSG_EDITOR_FORMAT) = EDITOR_FORMAT_HTML
sItem.Send
I hope that helps,
Joe P.