One last Hurdle - Email - help

Hi,

I’ve looked at all the docs, and posts hear regarding sending email in WE and still cant get it to work.

I Have one Form, This form has various contaners in it that are made visible and invisable (it’s a wizard, Step by Step).

I have a property of the form: SMTPServer as SMTPSecureSocket

I have a lot of email sending routines in my desk top apps and they work great. In the WE the lack of events for SMTPSecureSocket to see what if there are any errors has me scratching my head as I can’t figure out what the issue is.

Here is the method that sends the email:


  Dim rs as RecordSet
  Dim Msg as New EmailMessage
  
  System.DebugLog("In Send Application")

  rs = Session.sesDB.SQLSelect("Select * from memapplications where memappkwy = " + Str(Session.gnRecNo))
 
  SMTPServer = New SMTPServer
  SMTPServer.Address = csBulkMailSMTPServer
  SMTPServer.Port = cnBulkEmailEmailPort
  SMTPServer.Username = csBulkMailSMTPUserID
  SMTPServer.Password = csBulkEmailSMTPPassword
  SMTPServer.ConnectionType = SMTPSecureSocket.SSLv23
  SMTPServer.Secure = True
  
  Msg.AddRecipient csEmailAddress
  System.DebugLog("Sending email to: " + csEmailAddress)
  Msg.subject = "Application Form - " + rs.Field("lastName").StringValue + ", " + rs.Field("firstName").StringValue + " " + rs.Field("middleName").StringValue
  Msg.BodyHTML = CreateMsg()
  SMTPServer.Messages.Append( Msg)
  SMTPServer.SendMail
  

How can you test if there was an error?

Thanks

Rich

SMTPSecureSocket most certainly has events. See its LR page. The way you’ve set this up, you’ll need to use AddHandler to get them.

But the secret here is that you need to create Timer and call SMTPServer.Poll while it’s working, i.e. until SMTPServer.Messages is empty and the MailSent, Error, or ServerError event is fired.

I have not had this issue with sending email through a web app. Where/how did you find this information?

Bob,

How do you do it? Do you see anything wrong with my code?

Brad, Use a timer, how exactly?

[quote=87249:@Bob Keeney]I have not had this issue with sending email through a web app. Where/how did you find this information?
[/quote]

Well, I use my same subclass I’ve used with desktop apps that incorporates the timer poll. Perhaps I don’t need to anymore. I probably missed this being fixed at some point if it has been.

[quote=87251:@Richard Albrecht]Brad, Use a timer, how exactly?
[/quote]

Create a Timer (not a WebTimer) as a property of your page. AddHandler an Action event. In that event, call SMTPServer.Poll. Turn the Timer off when mail has been sent or the SMTPServer errors out.

I thought you could only use Web Objects in WE.

I’m still learning these events, how do you use AddHandler?

Are you saying Call .Poll in The Timer?

Also what’s an LR page?

I put a breakpoint on the SMTPServer.SendMail and checked IsConnected, it was false. Added SMTPServer.Connect and checked again, was still false.

The error code was 103, what does that mean?

LR = Language reference

103 = domain name not found

LR --> Language Reference

See SocketCore.LastErrorCode in the LR. It’s a name resolution error. It can’t find your server.

I just found that out. The constant was blank, and that reminded me of a pet peave I have about the editor. If you pt a value in for the constant, and DON’T hit enter it doesn’t take it. Same is true of renaming a control on a form.

So I fixed That and IsConnected is False, And Last error is 0. The ip address is there also.

I started stepping throught he code and the Port Number changes when it calls Sendmail to 62945 from 465.

And last error is 0

Helllllppppp!

Can someone please try and help me solve this?

[quote=87232:@Richard Albrecht]I have a property of the form: SMTPServer as SMTPSecureSocket

I have a lot of email sending routines in my desk top apps and they work great. In the WE the lack of events for SMTPSecureSocket to see what if there are any errors has me scratching my head as I can’t figure out what the issue is.[/quote]

Instead of adding the SMTPSecureSocket as a property, do this :

  • Click “Insert” in the upper left corner of the IDE and select “Class”
  • Select the new Class1 in the left hand side of the IDE
  • In the inspector, change its name for SMTPServer
  • Click the pencil next to Super
  • In the dialog, enter SMTP in the search field
  • Select SMTPSecureSocket

When your new SMTPServer class is done, drag it over your page. You may need to change the name of the window instance from SMTPServer1 to SMTPServer.

SMTPServer will be available to all controls on the page as before, but now you can add events to the master class (the one you inserted) the way you would do with any standard control.

The error event is available as you can see here : http://documentation.xojo.com/index.php/SMTPSecureSocket

Hope this helps:)

[quote=87275:@Richard Albrecht]I started stepping throught he code and the Port Number changes when it calls Sendmail to 62945 from 465.
[/quote]
That’s actually a good sign. You’re establishing a tcp connection which the server has handed off to a random port for actual processing. Now you’re just not getting logged in.

I’ve had to use port 587 with gmail. 465 never worked for me with them.

Michael, I did exactly that, same result. However no error event fired.

Tim , This is our bulk email company and that is the same settings used in the desktop apps.

I think I have to call them, maybe they have traffic blocked from my ip.

I probably won’t get back to this till Monday, then I can call the bulk email company.

Thanks

I did not pretend having solved your bug. Just tried to help you add events to SMTPSender.

I regularly send email from a web app, but my code is different, so I cannot help you there. Sorry.

Michel . . . tried your solution. Got this error for property name (???): Parameters are not compatible with this function name.

Would not allow me to change SMTPserver1 to SMTPserver. SMTPserver1 is a control on my page.

ideas?

[quote=131827:@John Scanlan]Michel . . . tried your solution. Got this error for property name (???): Parameters are not compatible with this function name.

Would not allow me to change SMTPserver1 to SMTPserver. SMTPserver1 is a control on my page.

ideas?[/quote]

Indeed, I forget that you cannot use the same name as the class. rename the class to SMTPServer0 and you will be able to rename the instance on the page SMTPServer.

I’m pulling my hair out with this. The demo app works fine on the desktop, but fails in the web version. I can connect to the server fine, but it always comes back as user did not authenticate. I have tried every iteration of settings I can imagine. Maybe it is the exchange server I am trying to connect to…

Can anyone who has been successful sending emails through a web app, show some code that works?

I use this to send email via an Exchange Server. This code was pretty much borrowed from one of the examples.

The authentication can by tricky but this works with a server that requires an SSL connection.

Here are the declare header for a method to do the send:

ServerAddress as string, ServerPort as integer, ServerUID as string, ServerUPW as string, FromAddress as string, ToAdr as string, ToAdrCC as string, ToAdrBCC as string, Subject as string, BodyPlain as string, BodyHTML as string

Here is the actual code to do the send:

[code] 'Send email
Dim mail As EmailMessage
Dim i As Integer
Dim s As String
Dim ToAdrWK as string
Dim ToAdrCCWK as string
Dim ToAdrBCCWK as string
Dim MailSocket as new SMTPSecureSocket

// set up the socket
MailSocket.Address = ServerAddress
MailSocket.Port = ServerPort
MailSocket.ConnectionType = SSLSocket.TLSv1

MailSocket.Username = ServerUID
MailSocket.Password = ServerUPW

// populate the email message
mail = New EmailMessage
mail.FromAddress = FromAddress
mail.Subject = Subject
mail.BodyPlainText = BodyPlain
mail.BodyHTML = BodyHTML
mail.Headers.AppendHeader(“X-Mailer”,“Xojo SMTP Demo”)

// add recipients
ToAdrWK = ToAdr
s = ReplaceAll(ToAdrWK, “,”, Chr(13))
s = ReplaceAll(s, Chr(13)+Chr(10), Chr(13))
For i = 1 To CountFields(s, Chr(13))
mail.AddRecipient(Trim(NthField(s, Chr(13), i)))
Next

// add cc recipients
ToAdrCCWK = ToAdrCC
s = ReplaceAll(ToAdrCCWK, “,”, Chr(13))
s = ReplaceAll(s, Chr(13)+Chr(10), Chr(13))
For i = 1 To CountFields(s, Chr(13))
mail.AddCCRecipient(Trim(NthField(s, Chr(13), i)))
Next

// add bcc recipients
ToAdrBCCWK= ToAdrBCC
s = ReplaceAll(ToAdrBCCWK, “,”, Chr(13))
s = ReplaceAll(s, Chr(13)+Chr(10), Chr(13))
For i = 1 To CountFields(s, Chr(13))
mail.AddBCCRecipient(Trim(NthField(s, Chr(13), i)))
Next

'// add attachments - I don’t use attachments so this is commented out
'If fileFld.Text <> “” Then
'file = New EmailAttachment
'file.LoadFromFile(GetFolderItem(fileFld.Text))
'mail.Attachments.Append(file)
'End If

// send the email
MailSocket.Messages.Append(mail)
MailSocket.SendMail
System.DebugLog(“SendMail Queued”)
[/code]