Author |
|
loredano Newbie
Joined: 11 April 2018 Location: Italy
Online Status: Offline Posts: 15
|
Posted: 11 April 2018 at 7:53am | IP Logged
|
|
|
Hi,I want to use Smtp.SendJobs Method with multiple smtp (multithread).
I have 50 different smtp (one for customer) and read mail info from database foreach of them (I select all message to send with that smtp, 2000/3000) and send the message.
Can I use Smtp mailer in a parallel.foreach or is there a faster way to do this bulk send using different smtp for every group of messages?
Best Regards
Loredano
|
Back to Top |
|
|
Igor AfterLogic Support
Joined: 24 June 2008 Location: United States
Online Status: Offline Posts: 6104
|
Posted: 11 April 2018 at 7:58am | IP Logged
|
|
|
You can supply multiple SMTP servers for Smtp.SmtpServers collection, the load will automatically be distributed between those servers. Also, you'll need to set MaxThreadCount to -1, to make sure multithreading is enabled.
--
Regards,
Igor, Afterlogic Support
|
Back to Top |
|
|
loredano Newbie
Joined: 11 April 2018 Location: Italy
Online Status: Offline Posts: 15
|
Posted: 11 April 2018 at 8:07am | IP Logged
|
|
|
Ok,
I can use mailer.SmtpServers.Add("mail.domain.com", "jdoe", "secret"),
but every group of 2000/3000 messages must be sent using a given smtp (of the specific customer). So can I use Smtp mailer = new Smtp() in a multithreaded scenario, for example using Task Parallel Library (TPL) or I have to schedule the email messages, using every smtp one by one (i.e Send first all message of a customer using his smtp, then the messages of th second customer using his smtp and so on)?
Regards
Loredano
|
Back to Top |
|
|
Alex AfterLogic Support
Joined: 19 November 2003
Online Status: Offline Posts: 2206
|
Posted: 11 April 2018 at 8:09am | IP Logged
|
|
|
Ah, you need specific messages to go to specific servers.. Yes, you can create multiple Smtp instances and use them all-together in parallel.
Regards,
Alex
|
Back to Top |
|
|
loredano Newbie
Joined: 11 April 2018 Location: Italy
Online Status: Offline Posts: 15
|
Posted: 12 April 2018 at 5:59am | IP Logged
|
|
|
Ok,
so I can use this code Smtp mailer = new Smtp() in my method (traditional for cycle on every smtp server) and call: mailer.AddJob and mailer.SendJobsAsync so the cycle continue, then in mailer.JobsSuccessful I can get the message sent and the info in mergetable (a different table for every smtp) without concurrency problem in order to update the data in database (message-id, sent state of the message)? Or is better (faster) use a parallel.foreach and mailer.SendJobs?
|
Back to Top |
|
|
Alex AfterLogic Support
Joined: 19 November 2003
Online Status: Offline Posts: 2206
|
Posted: 12 April 2018 at 7:01am | IP Logged
|
|
|
I'd suggest something like this (for simplicity, I used pseudocode and two instances instead of N and array/loop):
Smtp[] mailers = new Smtp[2]
mailers[0] = new Smtp()
mailer[1] = new Smtp()
... // set Smtp servers for each instance
mailers[0].AddJob
mailers[1].AddJob
Task[] tasks = new Task[2];
tasks[0] = mailer.SendJobsAsync
tasks[1] = mailer.SendJobsAsync
await Task.WhenAll(tasks)
Message-IDs are generated in thread-safe manner.
Assuming that each mail merge uses its own table, no issue should be there either.
Only if you're using the same log file (in case if logging is on), this will cause concurrent I/O issues unless you set SyncRoot:
https://afterlogic.com/mailbee-net/docs/#logs_in_detail.html#Synchronize
Regards,
Alex
|
Back to Top |
|
|
loredano Newbie
Joined: 11 April 2018 Location: Italy
Online Status: Offline Posts: 15
|
Posted: 12 April 2018 at 7:32am | IP Logged
|
|
|
Ok thanks, this is a good way; so I can use also mailers.JobsSuccessful without concurrent I/O issues (each mail merge uses its own table).
Regards
Loredano
|
Back to Top |
|
|