Author |
|
tdhung80 Newbie
Joined: 09 May 2016 Location: Vietnam
Online Status: Offline Posts: 4
|
Posted: 09 May 2016 at 11:12pm | IP Logged
|
|
|
Hi,
I have some questions with SendAsync(),
1. How to pass a state object into?
2. How could use another TaskScheduler?
3. How to share the Smtp object for SendAsync()?
Any help will be very appreciated!
My Best,
Hung Tran
|
Back to Top |
|
|
Alex AfterLogic Support
Joined: 19 November 2003
Online Status: Offline Posts: 2206
|
Posted: 10 May 2016 at 3:12am | IP Logged
|
|
|
Hi,
1. You can't pass it with Async methods but usually it's not required because you can't anyway use the same Smtp instance simultaneously with many threads (so you anyway know which content it's executing now as there is only one).
2. Honestly saying, no idea. We never dealt with custom TaskScheduler implementations.
3. One Smtp instance = One SendSync (that's why #1 is not important). If you want to send multiple e-mails simultaneously, you can use AddJobs and then SendAsync. There you'll have context info specific for each particular email being sent, etc.
Regards,
Alex
|
Back to Top |
|
|
tdhung80 Newbie
Joined: 09 May 2016 Location: Vietnam
Online Status: Offline Posts: 4
|
Posted: 10 May 2016 at 9:43pm | IP Logged
|
|
|
Hi Alex,
Thank you for your quick reply.
I have done some tests with the component, the performance is really impressive. However, I have some questions.
1/ I couldn't find an official document about SMTP exception handling for Send methods (Send, SubmitToPickupFolder, SendAsync). Do you have any example for them? I found GetErrorDescription() method which will give me the error message, but that's a translated text, how could i need an error code?
2/ How could I manage number of SMTP connection?
3/ Some SMTP servers do not allow us to fetch more than 100 emails per connection, how could I handle it with the component?
My Best,
Hung Tran
|
Back to Top |
|
|
Alex AfterLogic Support
Joined: 19 November 2003
Online Status: Offline Posts: 2206
|
Posted: 11 May 2016 at 2:35am | IP Logged
|
|
|
Hi Hung,
1) When an exception occurs, you'll have an object of a class derived from MailBeeException. There are many classes which have additional properties depending on context of the error (e.g. SMTP server reply when the server returns an error).
The detailed manual:
http://www.afterlogic.com/mailbee-net/docs/#handle_exceptions_and_errors.html
2/3) The detailed manual:
http://www.afterlogic.com/mailbee-net/docs/#send_multiple.html
Properties to set are SmtpServer.MaxSendPerSessionCount, SmtpServer.MaxConnectionCount, Smtp.MaxThreadCount
Regards,
Alex
|
Back to Top |
|
|
tdhung80 Newbie
Joined: 09 May 2016 Location: Vietnam
Online Status: Offline Posts: 4
|
Posted: 11 May 2016 at 11:10am | IP Logged
|
|
|
Hi Alex,
Thank you for your quick reply.
1/ About exception handling, there is only an example for Send() synchronous method.
+ About SubmitToPickupFolder, I assume that's only exception about disk I/O and write permission. The queue will do its work, and put bad email into a folder called Bad. Could i know what is an error during sending that email?
+ About SendAsync(), I assume that the sending is started later, so the caller could not see the SMTP error, should i catch it in ContinueWith()?
2/ About MaxSendPerSessionCount / MaxConnectionCount, does it only work if Smtp objects references to the same SmtpServer object? In this case, does the Queue know when should create a new SmtpServer object?
3/ About a custom task scheduler, I ask this because the default task scheduler is being shared by many others, so that will be inefficient if there are too many tasks in queue. At the moment, SendAsync() will create a task and start it immediately, is it possible to configure to not start it automatically, so that i could use the Task API syntax like SendAsync().Start(my scheduler) to specific my task scheduler.
My Best,
Hung Tran
|
Back to Top |
|
|
Alex AfterLogic Support
Joined: 19 November 2003
Online Status: Offline Posts: 2206
|
Posted: 11 May 2016 at 11:48am | IP Logged
|
|
|
Hi Hung,
Quote:
1/ About exception handling, there is only an example for Send() synchronous method. |
|
|
1) SendAsync exception is identical. If you need samples which feature Async methods, you can find them in My Documents/MailBee.NET Objects/Samples. Those which are for .NET 4.5 utilize Async methods.
Quote:
About SubmitToPickupFolder, I assume that's only exception about disk I/O and write permission. The queue will do its work, and put bad email into a folder called Bad. Could i know what is an error during sending that email? |
|
|
SubmitToPickupFolder itself does not do it (putting bad email in Bad). It's MailBee.NET Queue app which does. MailBee.NET Queue internally uses SubmitToPickupFolder but it does much more than that. It's shipped with the full source code so that you can use it for your needs.
Quote:
About SendAsync(), I assume that the sending is started later, so the caller could not see the SMTP error, should i catch it in ContinueWith()? |
|
|
Send starts immediately (same does SendAsync, as async methods behave identically, I will use shorter names for brevity).
AddJob and SendJobs is the pair which makes deferred send (if you need this). First you create a pool of jobs with AddJob calls and then use SendJobs to start the sending process. SendJobs, however, starts immediately (it's just that you call it later).
To the moment when Send or SendJobs finishes (of if await SendAsync/SendJobs is done), all errors have already occurred and you'll get your exceptions. SendJobs, as it can send multiple emails at once, is more complex as it does not stop on a single error (to avoid situation when failure of a single email stops everything). The docs (Reference and Developer's Guide) explain this in more detail.
Quote:
About MaxSendPerSessionCount / MaxConnectionCount, does it only work if Smtp objects references to the same SmtpServer object? In this case, does the Queue know when should create a new SmtpServer object?
|
|
|
They are for single Smtp instance. However, with SendJobs you can use single instance to send many emails at once (including many simult. threads). So, no need to share SmtpServer object between multiple Smtp instances.
Quote:
About a custom task scheduler, I ask this because the default task scheduler is being shared by many others, so that will be inefficient if there are too many tasks in queue. |
|
|
Internally, our async methods consist of async methods of .NET framework. Shortly speaking, SendAsync internally does Socket.ConnectAsync, etc. So they completely rely on task orchestration used by .NET's own async methods (from System.Net.Sockets and System.IO namespaces).
Regards,
Alex
|
Back to Top |
|
|
tdhung80 Newbie
Joined: 09 May 2016 Location: Vietnam
Online Status: Offline Posts: 4
|
Posted: 15 May 2016 at 1:53am | IP Logged
|
|
|
Hi Alex,
Thank you for your explanation.
About MaxThreadCount, could you let me know when Smtp needs more than one thread to send? Is the property valid for SendAsync / SendJobs scenarios only?
My Best,
Hung Tran
|
Back to Top |
|
|
Alex AfterLogic Support
Joined: 19 November 2003
Online Status: Offline Posts: 2206
|
Posted: 15 May 2016 at 1:26pm | IP Logged
|
|
|
Hi Hung,
Smtp can send multiple messages simultaneously with SendJobs/SendJobsAsync. MaxThreadCount comes into play then.
Also, even a single message can be sent in multi-threaded manner if it's direct send mode (rather than sending via SMTP relay) and the message is addressed to multiple recipients (more exactly, when these recipients belong to different domains). Sending to MXes of these recipients can occur in parallel.
Regards,
Alex
|
Back to Top |
|
|