SMTPSecureSocket addhandler error


I have this code in the Windo Open Event:

  SMTPServerMail = New SMTPSecureSocket
  AddHandler SMTPServerMail.MailSent, AddressOf MailSentEvent

SMTPServerMail is a Property with the type set to: SMTPSecureSocket

I’m getting a compile error:

Type mismatch error. Expected delegate(SMTPSecureSocket), but got Delegate( )


Whats MailSentEvent look like ?

When using addressof you need to pass the object class to the handler as the first parameter. e.g. Sender As SMTPSecureSocket.

Thanks Wayne, that was it!

YOU never pass anything
It needs to be declared with an instance as the first parameter as that’s how the RUNTIME calls whatever event you’re defining
You never call this event directly so YOU never pass anything
The runtime calls the event this way

Thats why I asked what MailSent looked like

@Norman Palardy

It looks like:

	Sub MailSentEvent(Sender As SMTPSecureSocket)
		  Call UpdateTransaction("", "", "App Sent")
		  MsgBox("In Sent")
	End Sub

It compiles but it doesn’t fire.

whats the code to start sending ?
and you dont make the thing go out of scope before all are sent ?
you do poll the socket ?

as you can see there are a few reasons it might not get called - primarily the send queue never empties for some reason

Here’s the code where the email gets sent.

SMTPServerMail is a Property, Type SMTPSecureSocket
In the window open event:

  SMTPServerMail = New SMTPSecureSocket
  AddHandler SMTPServerMail.MailSent, AddressOf MailSentEvent

In a method the Mail is sent:

  SMTPServerMail.Address = "localhost" 'csBulkMailSMTPServerMail
  SMTPServerMail.Port = 25 'cnBulkEmailPort
  SMTPServerMail.Username = ""   'csBulkMailSMTPUserID
  SMTPServerMail.Password = ""   'csBulkEmailSMTPPassword
  System.DebugLog("Last Error: " + Str(SMTPServerMail.LastErrorCode) )
  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()
  SMTPServerMail.Messages.Append( Msg)
  Call UpdateTransaction("", "", "Sending App")

Have I missed something?

What happens AFTER SMTPServerMail.SendMail is called ?
Does the window close ?

No The WebPage does not close, unless the user closes it, but I don’t.

one way to test why they dont get sent is to put a loop right after sendmail that just polls it periodically until bytes left to send = 0

I’ll try it tomorrow and report.

Thanks for the help Norman!

I put the loop in and the event still didn’t fire.

 While SMTPServerMail.BytesLeftToSend > 0
  MsgBox("Out of Polling")

Have you added handlers for the other events as well ?
I’m wondering if there’s errors etc that are occurring but since there’s no handler you don’t know it

No but the email is going through.

I will try adding the other events and let you know.

ah so only the event that is when all mails have been sent isnt firing

hmmm …

there’s only one email though ?

bytes left to send is for one message so maybe poll like

 While SMTPServerMail.Messages > 0

  MsgBox("Out of Polling")

Tried that and got Type Missmatch Expected class EmailMessage, but got int32 so went back to BytesLeftToSend.

I’ve implemented more events, will let you know.

I added ConnectionEstablished and Servererror, Neither of them fired.

well connection established not firing would be an issue
no emails will be sent without connection

Except I can confirm that an email was sent.