HTML construct shows as plain text in email body (1 Viewer)

Timax

Registered User.
Local time
Today, 06:19
Joined
May 14, 2015
Messages
33
I used HTML construct when sending email in email body but receive as a plain text. What am I missing? here is my code:

Function BuildHtmlBody(SQLStatement As String, ByVal Name As String)

Dim html, State, Qty

html = "<!DOCTYPE html><html><body>"
html = html & "<div style=""font-family:'Segoe UI', Calibri, Arial, Helvetica; font-size: 14px; max-width: 768px;"">"
html = html & "Dear {Name}, <br /><br />Please receive statement. <br />"
html = html & "Here is current status:<br /><br />"
html = html & "<table style='border-spacing: 0px; border-style: solid; border-color: #ccc; border-width: 0 0 1px 1px;'>"
Dim sql

Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
sql = SQLStatement
Set rs = db.OpenRecordset(sql, dbOpenSnapshot)

rs.MoveFirst

Do While Not rs.EOF

State = Trim(rs!StateName)
Qty = Trim(rs!RealQty)

html = html & "<tr>"
html = html & "<td style='padding: 10px; border-style: solid; border-color: #ccc; border-width: 1px 1px 0 0;'>" & State & "</td>"
html = html & "<td style='padding: 10px; border-style: solid; border-color: #ccc; border-width: 1px 1px 0 0;'>" & Qty & "</td>"
html = html & "</tr>"

rs.MoveNext
Loop

html = html & "</table></div></body></html>"
BuildHtmlBody = html

End Function
 

isladogs

MVP / VIP
Local time
Today, 13:19
Joined
Jan 14, 2017
Messages
18,186
What method are you using to send email from Access?
Check whether the code used to send the email is sending it as HTML or plain text.

If not it doesn't matter what HTML you use in your code, it will go as plain text as that is the default I believe.

If you need it, I have code to send HTML email from Access using CDO
 

Minty

AWF VIP
Local time
Today, 13:19
Joined
Jul 26, 2013
Messages
10,355
As a note of caution for your, this line of code;
Code:
Dim html, State, Qty

Dims all the variables as Variant data types .
in Access you have to declare variables explicitly to set a data type e.g.

Code:
Dim HTML as String, State as String, Qty as Integer
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:19
Joined
Oct 29, 2018
Messages
21,358
Hi,

My company has a group policy enforced to convert all incoming emails as plain text for security. Perhaps your company does to? Try sending your email to a non-company address.

Just my 2 cents...
 

Timax

Registered User.
Local time
Today, 06:19
Joined
May 14, 2015
Messages
33
As a note of caution for your, this line of code;
Code:
Dim html, State, Qty

Dims all the variables as Variant data types .
in Access you have to declare variables explicitly to set a data type e.g.

Code:
Dim HTML as String, State as String, Qty as Integer

Thank you, Changed that.
 

Timax

Registered User.
Local time
Today, 06:19
Joined
May 14, 2015
Messages
33
What method are you using to send email from Access?
Check whether the code used to send the email is sending it as HTML or plain text.

If not it doesn't matter what HTML you use in your code, it will go as plain text as that is the default I believe.

If you need it, I have code to send HTML email from Access using CDO

Can you please send me CDO that sends HTML? I am using CDO to send but don't see any options for HTML or plain text.
 

Timax

Registered User.
Local time
Today, 06:19
Joined
May 14, 2015
Messages
33
Hi,

My company has a group policy enforced to convert all incoming emails as plain text for security. Perhaps your company does to? Try sending your email to a non-company address.

Just my 2 cents...

I just used outside email and still not getting HTML. These is got to be a way to send it as HTML
 

Timax

Registered User.
Local time
Today, 06:19
Joined
May 14, 2015
Messages
33
ok, I figured this out! I changed to .HTMLBody = strMessage and it worked! Thank you
 

Users who are viewing this thread

Top Bottom