views:

287

answers:

3

I want to add some html in an email. I've tried the following.

vFromName = "someone"
vFromAddress = "someemail"
vTo = "recipient"
vSubject="someSubject"
vBodyofemail = "<html><table><tr><td><b>SomeText</b></td></tr></table></html>"

Call SendMail()

sub SendMail()
  'change to address of your own SMTP server
  strHost = "mail.internal.rouses.com"
  Set Mail = Server.CreateObject("Persits.MailSender")
  'enter valid SMTP host
  Mail.Host = strHost
  'From eMail address
  Mail.FromName = vFromName
  'From address
  Mail.From = vFromAddress 
  'To eMail address
  Mail.AddAddress vTo
  'message subject
  Mail.Subject = vSubject
  'message body
  Mail.Body = vBodyOfEmail
 Mail.Send
end sub

How can i do this? I've tried Mail.HtmlBody but that doesn't work either. The email is sent but all i see are the tags where the html is.

+3  A: 

According to this page you need to set the IsHTML flag to true.

strHTML = "Hello world"

Mail.IsHTML = True
Mail.Body = "<HTML><BODY><CENTER>" & strHTML & "</CENTER></BODY></HTML>"
C. Ross
Thanks. But this didn't work.
Eric
This worked. My issue was that this function is in a few places and the one I was editing was not the correct function called. Thank you.
Eric
But then how is the plain-text (within the same message) defined?
Arjan
Eric
Hmmm, I doubt a few newlines will make Persits.MailSender generate a MIME Boundary. Did you actually test that with a few clients? I can imagine that any text added after the closing </HTML> tag will not be shown in HTML mode, but I doubt the HTML version will be hidden when viewing the message as plain text...
Arjan
A: 

Not an answer to your question, but shouldn't all messages include plain text as well? Without plain text, you'll surely get a higher spam score.

(And people like myself prefer to switch to plain text if your HTML/CSS is not rendered well. See Guide to CSS support in email clients (2008), and the list at the Email Standards Project.)

Arjan
It does. I just didn't put it in the code above.
Eric
...but then how would you put both the plain text and the HTML in the Mail.Body property? I wonder if Persits.MailSender is the way to go.
Arjan
+3  A: 

Try adding this line above the send call.

Mail.IsHTML = true

Without it, the Mail object defaults to standard text and whatever is typed into the Body property will be rendered in the email as text.

RSolberg
This worked. My issue was that this function is in a few places and the one I was editing was not the correct function called. Thank you. C. Ross answered it first so I'll give him the answer. but I'll give you +1
Eric
The function being in a few places sounds a bit like a code smell :)
RSolberg