Hi,
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( )
Thanks
Norman_P
(Norman P)
October 21, 2015, 7:03pm
2
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!
Norman_P
(Norman P)
October 21, 2015, 7:13pm
5
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.
Norman_P
(Norman P)
October 21, 2015, 7:59pm
7
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")
SMTPServerMail.SendMail
Have I missed something?
Norman_P
(Norman P)
October 21, 2015, 8:25pm
9
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.
Norman_P
(Norman P)
October 21, 2015, 8:28pm
11
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
SMTPServerMail.Poll
WEnd
MsgBox("Out of Polling")
Norman_P
(Norman P)
October 22, 2015, 2:51pm
14
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.
Norman_P
(Norman P)
October 22, 2015, 3:46pm
16
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
SMTPServerMail.Poll
Wend
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.
Norman_P
(Norman P)
October 23, 2015, 2:47pm
19
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.