Rank: Newbie
Groups: Registered
Joined: 7/18/2013(UTC)
Posts: 0
Location: Zagreb
Thanks: 1 times
The example for using EASendMail SMTP component asynchronously demonstrates using AsyncWaitHandle to block execution until the SendMail operation completes, like this:
SmtpClientAsyncResult oResult = oSmtp.BeginSendMail(oServer, oMail, null, null); while (!oResult.IsCompleted) { oResult.AsyncWaitHandle.WaitOne(50, false); } oSmtp.EndSendMail(oResult); Is it possible to use callback delegate? I have tried to use the code like following:
SmtpClientAsyncResult oResult = oSmtp.BeginSendMail(oServer, oMail, new AsyncCallback(AsyncSendCompletedCallback), oSomeStateObject); //... private void AsyncSendCompletedCallback(IAsyncResult result) { try { EASendMail.SmtpClientAsyncResult ar = result as EASendMail.SmtpClientAsyncResult; ar.SmtpClientInstance.EndSendMail(ar); } catch( EASendMail.SmtpTerminatedException ) { } catch( Exception ex ) { } } This works fine when communication with SMTP completes without problems. If there is a communication error, however, the operation will never complete, i.e. callback procedure seems to newer get called. For example, if wrong password is set, the opeation continues and various events are raised as expected, until the SMTP server responds with status code 535 Bad authentication. Then everything stops, and the callback procedure is never called. This does not happen when AsyncWaitHandle is used.
Can you confirm that callback delegate method is actually supported?
Rank: Administration
Groups: Administrators
Joined: 11/11/2010(UTC) Posts: 1,153
Thanks: 9 times Was thanked: 55 time(s) in 55 post(s)
Thank you very much for reporting this problem, after I double-checked the code, it is a bug in the callback. In current version, the callback delegate is not invoked if there is an exception. I will send you a quick fix at tomorrow. Thanks again.
1 user thanked ivan for this useful post.
Rank: Newbie
Groups: Registered
Joined: 7/18/2013(UTC)
Posts: 0
Location: Zagreb
Thanks: 1 times
Thanks for the very quick reply.
I have temporarily cirumvented the problem by using BackgroundWorker as follows:
bwWaitAsync = new BackgroundWorker(); bwWaitAsync.DoWork += bwWaitAsync_DoWork; bwWaitAsync.RunWorkerCompleted += bwWaitAsync_RunWorkerCompleted; //... bwWaitAsync.RunWorkerAsync(oSmtp.BeginSendMail(oServer, oMail, null, oSomeStateObject)); //... void bwWaitAsync_DoWork(object sender, DoWorkEventArgs e) { EASendMail.SmtpClientAsyncResult result = e.Argument as EASendMail.SmtpClientAsyncResult; result.AsyncWaitHandle.WaitOne(); e.Result = result; } void bwWaitAsync_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { AsyncSendCompletedCallback(e.Result as EASendMail.SmtpClientAsyncResult); } This is not the optimal solution as it creates one more thread, but works fine.
So, there is no rush to fix the bug, I can wait until the next regular release.
Thank you again!
Edited by user Thursday, July 18, 2013 6:31:59 AM(UTC)
| Reason: Not specified
Rank: Administration
Groups: Administrators
Joined: 11/11/2010(UTC) Posts: 1,153
Thanks: 9 times Was thanked: 55 time(s) in 55 post(s)
Hi, I have sent you a quick fix by private message, you can download and test it. If it is ok, please kindly let me know, then i can add this fix at next release. Thank you very much
Rank: Newbie
Groups: Registered
Joined: 7/18/2013(UTC)
Posts: 0
Location: Zagreb
Thanks: 1 times
In my development environment, using first a wrong password, and then an unexisting host, EASendMail40.dll worked as expected, errors being reported as exceptions from EndSendMail. I will be deploying the program at one site tomorrow, and will have it run experimentally during the next week. Will report if any issues arrise. Thank you, and greetings!
Rank: Administration
Groups: Administrators
Joined: 11/11/2010(UTC) Posts: 1,153
Thanks: 9 times Was thanked: 55 time(s) in 55 post(s)
Just let you know, we just released 7.0.0.2, this version includes the fix for callback.
Forum Jump
EmailArchitect Support
Email Component Development
- EASendMail SMTP Component - .NET Version
- EASendMail SMTP Component - Windows Store Apps
- EASendMail SMTP ActiveX Object
- EAGetMail POP3 & IMAP4 Component - .NET Version
- EAGetMail POP3 & IMAP4 ActiveX Object
Exchange Server and IIS SMTP Plugin
- DomanKeys/DKIM for Exchange Server and IIS SMTP
- Disclaimer and S/MIME for Exchange Server and IIS
EmailArchitect Email Server
- EmailArchitect Email Server (General)
- EmailArchitect Email Server Development
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.