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 = “smtp.YOURSERVER.com”
// The port number of the server:
SMTPSocket1.port = 25
// Your username for the server, if nec.
SMTPSocket1.Username=”yourname@yourserver.com”
// Your password:
SMTPSocket1.Password=”yourpwd”// Create a new message:
mail = New EmailMessage
// The address you want it to come from:
mail.fromAddress= “your@address.com”
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 “person@somwehere.com”
// cc someone:
mail.addCCRecipient “another@recipient.com”// Add it to list of messages:
SMTPSocket1.messages.append mail
// Send message:
SMTPSocket1.SendMail// Wait for the sending to be done if you’re going to send another
while SMTPSocket1.BytesLeftToSend > 0
  SMTPSocket1.poll
wend
Please correct any boneheaded errors I’ve made. Thanks.








