HTML email from Squeak using Seaside
Recently, as part of a Seaside-based application running within Squeak, I wanted to send HTML-formatted notification emails when certain things happened within the application.
It turns out that Squeak has a built-in SMTP client library, which with a small amount of glue can be used with Seaside’s HTML renderer to send HTML formatted emails using code similar to that used when rendering Seaside website components.
sendHtmlEmailTo: toEmailAddressString
from: fromEmailAddressString
subject: subjectString
with: aBlock
| m b bodyHtml |
m := MailMessage empty.
m setField: 'from' toString: fromEmailAddressString.
m setField: 'to' toString: toEmailAddressString.
m setField: 'subject' toString: subjectString.
m setField: 'content-type' toString: 'text/html'.
b := WAHtmlBuilder new.
b canvasClass: WARenderCanvas.
b rootClass: WAHtmlRoot.
bodyHtml := b render: aBlock.
m body: (MIMEDocument contentType: 'text/html' content: bodyHtml).
SMTPClient deliverMailFrom: m from
to: {m to}
text: m asSendableText
usingServer: 'YOUR.SMTP.SERVER.EXAMPLE.COM'.
The
aBlock
argument should be like the body of a WAComponent’s
renderContentOn:
method. Here’s an example:
whateverObjectYouInstalledTheMethodOn
sendHtmlEmailTo: 'target@example.com'
from: 'source@example.org'
subject: 'Hello, world'
with: [:html |
html heading level3 with: 'This is a heading'.
html paragraph with: 'Hi there!']

Planet Ciaran (planetciaran) 's status on Tuesday, 08-Sep-09 19:44:20 BST - MicroCiaran
on 08/09/09 at 6:45 pm
[...] tonyg – HTML email from Squeak using Seaside – http://www.lshift.net/blog/2009/09/08/html-email-from-squeak-using-seaside [...]
Duncan
on 08/09/09 at 6:58 pm
You know about the cascades syntax, right?
tonyg
on 08/09/09 at 9:50 pm
@Duncan: yes; why do you ask?