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.

Canavar
  • 47,715
  • 17
  • 91
  • 122
Eric
  • 7,930
  • 17
  • 96
  • 128
  • What doesn't work? Does the e-mail send and you see html, or do you not get an e-mail at all? – C. Ross Jul 03 '09 at 15:03
  • The email is sent. I just see the html-tags though...not what they are supposed to do. – Eric Jul 03 '09 at 15:06

3 Answers3

3

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
  • 31,137
  • 42
  • 147
  • 238
  • 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 Jul 03 '09 at 15:41
  • But then how is the plain-text (within the same message) defined? – Arjan Jul 03 '09 at 16:21
  • 1
    You would simply put this at the end of the html string: & chr(10) & chr(13)& chr(10) & chr(13) _ then &"plain-text" it works. – Eric Jul 03 '09 at 16:45
  • 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

    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 Jul 04 '09 at 14:31
3

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
  • 26,821
  • 23
  • 116
  • 160
  • 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 Jul 03 '09 at 15:40
  • The function being in a few places sounds a bit like a code smell :) – RSolberg Jul 03 '09 at 15:56
0

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
  • 22,808
  • 11
  • 61
  • 71
  • ...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 Jul 03 '09 at 15:29