Greetings - first post, here, as I usually use the NUG.
Trying to make an e-mail based event notifier for remote scientific equipment with satellite internet. I have set up and validated a SendGrid account. Currently testing from a Mac on a large university network. My test code is as follows:
//set up the socket, Socket1 is an smpt socket
Dim Socket1 as SMTPSocket = new SMTPSocket
Socket1.Address = "smtp.sendgrid.net
Socket1.Port = 587
Socket1.Username = myusername
Socket1.Password = mypassword
Socket1.connect
If Socket1.LastErrorCode > 0 then
MsgBox "The SMPTPSocket in SendMail has detected an error. The ErrorCode is "+str(Socket1.LastErrorCode)
return false
End if
If Socket1.IsConnected then
MsgBox "Successful connection to the specified SMTP Server!! WAHOO!"
else
MsgBox "OOOPSIE! The connection to the SMTP Server was not successful!"
return false
End if
Socket1.Disconnect //temp for debugging
After the connect operation, there is no non-zero LastErrorCode. It shows a port number other than 587, which, from the Xojo docs, sounds like it was bound to a port at the other end. But, it shows that it IsConnected is false. So, a couple of questions:
Is this a valid test (trying to “connect” to see if the connection is possible)?
Is my code ok?
Is there something I am missing?
Or, are my expectations not realistic?
Thanks
Jim Wagner
Oregon State University & Oregon Research Electronics
I loop for 1000000 microseconds before the LastErrorCode test.
It then returns error=102 (Lost Connection). Is 1 second too long?
Does this have any implications about how the message is constructed and sent? For example, should the message be constructed before the connection attempt? Is it necessary to wait after the connection request to send the message?
//set up the socket, Socket1 is an smtp socket
Dim Socket1 as SMTPSocket = new SMTPSocket
Socket1.Address = "smtp.sendgrid.net
Socket1.Port = 587
Socket1.Username = myusername
Socket1.Password = mypassword
//Here’s the part that’s new
Dim mail as New EmailMessage
mail.fromAddress="test@test.com"
mail.subject="subject"
mail.bodyPlainText = "test"
// send the email
Socket1.messages.append mail
Socket1.sendMail