Joho the Blogrealbasic Archives - Joho the Blog

February 7, 2010

How to send email using RealBasic

It took a bunch of googling (thanks!) and some experimentation, but the following seems to work on a Mac (snow leopard) to send email programmatically, using RealBasic:

Dim mail as EmailMessage
Dim SMTPSocket1 as SMTPSocket

// create an instance:
SMTPSocket1 = new SMTPSocket

// The name of an available SMTP server:
SMTPSocket1.address = “”
// The port number of the server:
SMTPSocket1.port = 25
// Your username for the server, if nec.
SMTPSocket1.Username=”[email protected]
// Your password:

// Create a new message:
mail = New EmailMessage
// The address you want it to come from:
mail.fromAddress= “[email protected]
mail.subject= “Your Subject”
// The message:
mail.bodyPlainText = “Testing. Testing. Is this thing on?”
// Alternatively, encode message in HTML:
mail.BodyHTML = “<u>Testing</u> Is this thing <blink>on</blink>?”
// If you want a header:
mail.headers.appendHeader “X-Mailer”,”REALbasic SMTP”

// The address you’re sending it to:
mail.AddRecipient “[email protected]
// cc someone:
mail.addCCRecipient “[email protected]

// Add it to list of messages:
SMTPSocket1.messages.append mail
// Send message:

// Wait for the sending to be done if you’re going to send another
while SMTPSocket1.BytesLeftToSend > 0

Please correct any boneheaded errors I’ve made. Thanks.

Comments Off on How to send email using RealBasic