HTML Emails

I’ve seen a few users over the years ask about how to create HTML emails and stumbled onto an article about it tonight that I thought might be interesting to someone.


Thanks for this! This is awesome! I have tried a little bit to figure it out, but haven’t made any progress. What’s the best way to send an HTML email through Xojo? Obviously it’s not easy to make the HTML a string for the Xojo code, and I haven’t succeeded in finding a way to pull it from a file and include the images. Any advice?

Use CURL with the MBS plugin or the Chilkat plugin.


In writing my app (an email client) I started with the RFCs which describe the structure of an email, and how you can send a mail that has a text part, an html part, and inline and attached files too.

Here is an incomplete list of the RFCs that may be consulted:

a) RFC 5034 POP3
b) RFC 2821 SMTP
c) RFC 5322 Internet Message Format
d) RFC 2045, 2046, 2047, 2048, 2049 and 2557 (MIME), 2183, and 2231
e) RFC 2392 Content-Id URL


With CURLEMailMBS class in MBS Xojo CURL Plugin, you can just pass HTML to the plugin and we build the whole structure around for you.

Firstly: HTML designed Emails will be the first ones to be sorted out. Secondly: Many Clients won’t display them because all included base64 contents for embedded images or even more worse: external references will be stripped out leaving the mails quite broken and usable. Thridly: Many Coorporations store such eMails in their long-time-archieves and create tags or parse them for projects or departments by keywords. HTML Mails are the most ones obvious usual suspects, sorted out straight into “uncategorized” what means, nobody will find anything nor will search for them.

It’s a best practise to use simple, unformated text-mails. Stick to it!

Rather than using fancy, funky styled emails try to improve your mailservers or email infrastructure.
A good starting point is Feel free to compare my mailserver with something else:

As for me, mailing letters should be primarily interesting to recipients. Nobody likes spam. Layout is just as important. Nobody needs a bare wall of text, but a million images that take a long time to load on the mobile Internet are not very good. So, the point is not even in choosing a service, but in building the right strategy.

I contract for a company with a Xojo console application that automatically sends email to suppliers when their certificates have expired. They used to be sent as plain text and were often (accidentally) ignored by the supplier or treated as spam.

When I updated them to use pretty HTML emails with a linked company logo and formatted text their reply rate went so high they no longer need to chase the supplier for the new certificates.


Depends really. I tend to ignore most html emails. A text one is more likely to have been generated by a real human.

Has anyone figured out a way to send HTML emails using via AppleScript? It seems like it used to work years ago but has been broken in macOS.

A demo applescript that doesn’t work for me in 10.14:

set theHTML to "<html><body><h1>Hi there (HTML)</h1><body></html>"
set theBody to "Hi There (text)"
set eSender to ""
set eSubject to "Testing HTML"
set eName to "Alice Alison"
set eMail to ""

tell application "Mail"
	##Create the message
	set theMessage to make new outgoing message with properties {sender:eSender, subject:eSubject, visible:true}
	##Set a recipient
	tell theMessage
		set html content to theHTML
		set content to theBody
		make new to recipient with properties {name:eName, address:eMail}
		##Send the Message
		## send
	end tell
end tell

When run, I get a new mail message, but only the plain text content shows up.

You can use NSSharingServiceItemsMBS with an NSAttributedStringMBS object like this:

// compose email
Dim items As New NSSharingServiceItemsMBS

// styled text from text area control
Dim tv As NSTextViewMBS = TextArea1.NSTextViewMBS
items.AddAttributedString tv.textStorage

// find service
Dim service As New NSSharingServiceMBS("")

service.subject = "Test Email"
service.setRecipients Array("test@test.test")

service.performWithItems items
1 Like

Thank you, Greg.

I’ve made quite a few of these over the years but it’s always nice to have a more recent writeup.

I personally am not a fan of HTML emails but that’s irrelevant, since it’s the way all emails work by default and the way companies and people expect email to behave (I mean being able to style it, people don’t normally know what “html email” means).

Not having nor using HTML email has become more and more a sign of “something is wrong” for normal users. Explaining potential downsides of HTML email is wasted time and effort when they use it every single day continuously without facing most of them.

It’s a good thing, though, that it has more or less standardized by now (with the caveats and limitations forced by the medium). It was a lot more of the wild west and “styled email” could mean HTML or RTF, and “HTML” didn’t mean the same for all clients either. By now it’s pretty safe that HTML email generated in one place will be readable in another.

I also prefer the older style of quoting and replying but top-replying also has become the norm. We old farts need to just accept it and move on.

This is not true. The emails I receive on the SQLite Users Mailing List, for example, are text only and contain no HTML.

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.