Do...Loop with SMTPSocket

Trying to send the email 6 times to myself but it only emailed once.
I know that it disconnect after sending…Is there anyway to reconnect and email again for a few times depending on my Do…Loop?

Dim i As Integer
Do Until i = 5
msgbox "This is message " + str(i)

SendMailSocket.Address = "SMTP Email Server" // your SMTP email server
SendMailSocket.Port = 587 // Check your server for the property port # to use
SendMailSocket.Username = "SMTP USERNAME"
SendMailSocket.Password = "SMTP PWD"

// Create the actual email message
Dim mail As New EmailMessage
mail.FromAddress = ""
mail.Subject = "Test Email from Xojo" + str(i)
mail.BodyPlainText = "Hello, World!"
mail.Headers.AppendHeader("X-Mailer", "Xojo SMTP Example") // Sample header
mail.Headers.AppendHeader("Received", "Xojo SMTP Example") // Sample header
mail.Headers.AppendHeader("Message-Id", "")

// Add the message to the SMTPSocket and send it

i = i + 1


Why would you want to do this? Add the recipients and be done.

Do you come from AppleScript?

for i as integer = 1 to 6

is a bit more concise than the awkward do loop.

Thank your the reply.
Actually, I have a list of email addresses of friends and would like to email out to them with the same content but with a little personalized touch.
Wants the program to read the list from a listbox and send email to each of them directly.

You can add invididual messages to the socket and send them out all at once.

Out got it working!
My problem is with the subject. I want to send Asian language in the subject.
Any encoding tip?

Very good. Encoding in a subject is done in a special way. For instance, “smörebröd” becomes


Here is something on this topic:

Then you need to encode with UTF-8 Quoted Printable.

MBS has a Plugin Method for this: EncodeEmailSubjectMBS

Or better send or receive email with MBS CURL plugin.

Thank very much to every for the valuable input.
Special thanks to Beatrix W.

The encoding on the subject heading and body text works great!