Formatting E-mail Using Code

graviz

Registered User.
Local time
Yesterday, 23:47
Joined
Aug 4, 2009
Messages
167
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
 
this is certainly a tough question, and outlook doesn't use HTML like dreamweaver or other html editors do, but it is close.

I tried to do this once, but believe you me, it's a difficult thing to try and do. If you're not astute at HTML or you need to send quick messages, I would suggest doing it in a systematic way through code first, just like you're doing. You've obviously got the outlook properties down well.

I personally use the break tag a lot, but the problem with VBA is the lines have to be connected by the continuation character to even be valid.

I guess I didn't help much, but all I know to offer would be my own way of doing it.
 
this is certainly a tough question, and outlook doesn't use HTML ...
Umm, I would disagree. If you send in HTML format Outlook most certainly DOES use HTML and you can format the message using standard HTML code. The problem is that you do have to use the correct object and I don't think it is .HTMLBody. I don't have Outlook here at work to test, but I'll test tonight. We use Lotus Notes here at work <yuck!> and it just works with putting the code in to the normal body text, and the type of message has to be set to HTML.
 
Umm, I would disagree. If you send in HTML format Outlook most certainly DOES use HTML and you can format the message using standard HTML code. The problem is that you do have to use the correct object and I don't think it is .HTMLBody. I don't have Outlook here at work to test, but I'll test tonight. We use Lotus Notes here at work <yuck!> and it just works with putting the code in to the normal body text, and the type of message has to be set to HTML.


Thanks let me know.
 
I think you need the following in there up near the beginning:
.BodyFormat = olFormatHTML

Chris
 
I don't kmow if would suite you but one way, which is what I do, is to have Access use a Word doc for the body of the email and the Word doc takes it data from Access into bookmarks. Apart from bold type etc. the background colour of Word doc can be coloured/textured and that will appear in the email.

It can also be done if SMTP is used but Access must save the Word doc as HTML file and that is used as the email body.
 

Users who are viewing this thread

Back
Top Bottom