Hi,
I am trying to send a HTML email using B4J.
I have worked out how to send the email etc. but for some reason it's not displaying the email correctly.
I have a HTML page (demo.html) that I created using notepad and then I am opening that file in B4J and loading it into a string.
I then am converting variables in that file before sending it.
Here is my B4J Code I am using:
Based on the code above, I run the Sub 'FormatEmail' and it will then then open the demo.html page and replace the variables with something else and then send the email.
The problem is that the email looks like the following when viewing it in the inbox:
In fact it should look like the following HTML page:
Is there something I have missed in my B4J code to make it send the HTML page correctly ?
If I use the same HTML code (demo.html) and send it using another method (such as a email client) it sends the email fine. It only seems to have the issue using B4J to send the email.
Any one know what I have missed ?
(images and text in the sample email above is for just testing)
I am trying to send a HTML email using B4J.
I have worked out how to send the email etc. but for some reason it's not displaying the email correctly.
I have a HTML page (demo.html) that I created using notepad and then I am opening that file in B4J and loading it into a string.
I then am converting variables in that file before sending it.
Here is my B4J Code I am using:
B4X:
Sub SendEmail(ToEmail As String, Subject As String, body As String)
SMTP.To.Add(ToEmail)
SMTP.Sender = "Testing" & "<" & "FROM email is here" & ">"
SMTP.HtmlBody = True
SMTP.Body = body
SMTP.Subject = Subject
SMTP.Send
End Sub
Sub SMTP_MessageSent(Success As Boolean)
If Success Then
log("email sent")
Else
Log(LastException.Message)
End If
End Sub
Sub FormatEmail(username As String)
Dim MainPage As String = GetTemplate("demo.html") 'load the email template
MainPage = MainPage.Replace("$customer-firstname$", "Aaron")
SendEmail("The TO email is here","The Subject here",MainPage)
End Sub
Sub GetTemplate(Name As String) As String
If templates.ContainsKey(Name) Then Return templates.Get(Name)
Dim temp As String = File.ReadString(File.DirApp & "/email_templates", Name)
templates.Put(Name, temp)
Return temp
End Sub
Based on the code above, I run the Sub 'FormatEmail' and it will then then open the demo.html page and replace the variables with something else and then send the email.
The problem is that the email looks like the following when viewing it in the inbox:
In fact it should look like the following HTML page:
Is there something I have missed in my B4J code to make it send the HTML page correctly ?
If I use the same HTML code (demo.html) and send it using another method (such as a email client) it sends the email fine. It only seems to have the issue using B4J to send the email.
Any one know what I have missed ?
(images and text in the sample email above is for just testing)