Trying to send email/use SMTPSocket

I’m trying to send an email to myself to see if I can get this working. When I try this I get a NilObjectException on the lines

socket1.Address= "12.24.24.24.24" socket1.port = 25
What does that mean, why do I get that?
Thanks!

Here’s full code:

[code] Dim mail As EmailMessage
Dim file as EmailAttachment
Dim i as Integer
Dim s as String
'Socket1 is an SMTPSocket
socket1.Address= “12.24.24.24.24”
socket1.port = 25
socket1.username =“ramster59”
socket1.password = “hello123”

Dim mail as New EmailMessage
mail.fromAddress="hi@gmail.com"
mail.subject=“hi”
mail.bodyPlainText = “pls”
mail.bodyHTML = “?”
mail.headers.appendHeader “X-Mailer”,“Example SMTP Demo”
mail.addRecipient(“ram9@gmail.com”)

'file = New EmailAttachment
'file.loadFromFile GetFolderItem(fileFld.text)
'mail.attachments.append file

// send the email
socket1.messages.append mail
socket1.sendMail
MsgBox(“sent??”)
[/code]

[quote=152683:@Rami Hassan]I’m trying to send an email to myself to see if I can get this working. When I try this I get a NilObjectException on the lines

socket1.Address= "12.24.24.24.24" socket1.port = 25
What does that mean, why do I get that?
Thanks!

Here’s full code:

[code] Dim mail As EmailMessage
Dim file as EmailAttachment
Dim i as Integer
Dim s as String
'Socket1 is an SMTPSocket
socket1.Address= “12.24.24.24.24”
socket1.port = 25
socket1.username =“ramster59”
socket1.password = “hello123”

Dim mail as New EmailMessage
mail.fromAddress="hi@gmail.com"
mail.subject=“hi”
mail.bodyPlainText = “pls”
mail.bodyHTML = “?”
mail.headers.appendHeader “X-Mailer”,“Example SMTP Demo”
mail.addRecipient(“ram9@gmail.com”)

'file = New EmailAttachment
'file.loadFromFile GetFolderItem(fileFld.text)
'mail.attachments.append file

// send the email
socket1.messages.append mail
socket1.sendMail
MsgBox(“sent??”)
[/code][/quote]

Where do you create your Socket1 ?

socket1 is not in scope or has not been instantiated.

please make the socket part of a webpage or window, to keep it alive.

And sending is asynchronously. So your method will finish and than sending starts.

I just made a property that I made a ‘SMPTSocket’ called ‘socket1’.
I wasn’t sure what I was meant to do.

[quote=153179:@Rami Hassan]I just made a property that I made a ‘SMPTSocket’ called ‘socket1’.
I wasn’t sure what I was meant to do.[/quote]

You may want to put your Socket1 at the minimum as a session property, so it does not go out of scope when you try to send.

Here is what I use in an app on my site where users can send a message in a form :

app.theMailServer is an SMTPSocket property of app.

Dim mail As New EmailMessage mail.fromAddress= TextField1.Text mail.subject= "Match-Software.com / Message" mail.bodyPlainText = TextArea1.text mail.headers.appendHeader "X-Mailer","SMTP" mail.addRecipient "mymailaddress@mysite.com" app.theMailServer.messages.append mail app.theMailServer.sendMail msgBox "Your message has been sent. I will be processed as soon as possible. Thank you." showurl "http://Match-Software.com"

As you can see, it is very close to what you have so far. It has been on my site for over a year.

@Michel Bujardet
It’s fine to use on a Desktop app right?

  app.theMailServer.messages.append mail
  app.theMailServer.sendMail

This two lines give a NilObjectException? I made a ‘theMailServer’ property so why?

In the App.Open handler put

theMailServer = New SMTPSocket

[quote=153191:@Wayne Golding]In the App.Open handler put

theMailServer = New SMTPSocket

Ah that stops it erroring, thank you!
Do I remove the SMPTSocket property I already added or do I need it along with this line?

It doesn’t do anything though?
I put my email as the send and receive email, is that okay?

[quote=153205:@Rami Hassan]It doesn’t do anything though?
I put my email as the send and receive email, is that okay?[/quote]

I forgot this in App.Open. Sorry

theMailServer = New SMTPSocket theMailServer.Address = "mail.mydomain.com" theMailServer.Port = 26 theMailServer.Username = "myname@mydomain.com" theMailServer.Password = "mypassword"

[quote=153221:@Michel Bujardet] theMailServer = New SMTPSocket
theMailServer.Address = “mail.mydomain.com
theMailServer.Port = 26
theMailServer.Username = “myname@mydomain.com
theMailServer.Password = “mypassword”[/quote]

Thanks, what do I put as the Address, username and password though?
I put my email and a random username as password, is that wrong?
IsConnected was = false so?

I appreciate the help so far.

[quote=153223:@Rami Hassan]Thanks, what do I put as the Address, username and password though?
I put my email and a random username as password, is that wrong?
IsConnected was = false so?

I appreciate the help so far.[/quote]

Most SMTP servers today require the name of the user, usually in the form of his email address, and a password. I use my own site smtp server, but you may want to create an email address with your Internet provider. In general, you will get the necessary information such as port number and, username and password when you create the address.

Some companies provide free smtp. See https://duckduckgo.com/?q=free+smtp but they may not be as reliable, or mail may get blocked on arrival, as many of them are used by spammers.

[quote=153227:@Michel Bujardet]Most SMTP servers today require the name of the user, usually in the form of his email address, and a password. I use my own site smtp server, but you may want to create an email address with your Internet provider. In general, you will get the necessary information such as port number and, username and password when you create the address.

Some companies provide free smtp. See https://duckduckgo.com/?q=free+smtp but they may not be as reliable, or mail may get blocked on arrival, as many of them are used by spammers.[/quote]

Oh, I was under the impression I could create one simply with Xojo haha.
I’ll take a look at them; thanks for your help!