Reputation: 45
We are currently developing a system for a client who regularly sends batches of emails (can be anywhere from 5 to 500) to their customers. They have asked us if we are able to send it via their Office 365 account so that they can see the emails in their sent box. There is also the possibility that multiple users can trigger these emails at the same time to different customers, so we can't tell how many are going to be sent at any given time.
We have experience sending via SMTP, however not to this scale, and it looks like the sending limits would be an issue (30 per minute, 10,000 per day).
We have considered using a method to pool the emails going out and limit the rate they are sent to get around the limits (up to the 10,000 per day).
Is there a better way to send bulk mail using Office 365? Or are we trying to do something that it isn't designed to do?
Upvotes: 1
Views: 2003
Reputation: 1566
for the 30 mails per minute problem you can solve it just by creatring a Queued background service: enter link description here
Then you can just create a class EmailQueuedHostedService that inherits from QueuedHostedService and override the BackgroundProcessing method like this:
public class EmailQueuedHostedService : QueuedHostedService
{
private readonly ILogger<EmailQueuedHostedService> _logger;
private readonly TimersTimer _timer;
private int MailsSent = 0;
private const int MailsSentInMinute = 30;
public EmailQueuedHostedService(IBackgroundTaskQueue taskQueue,
ILogger<EmailQueuedHostedService> logger) : base(taskQueue, logger)
{
_logger = logger;
_timer = new TimersTimer(60 * 1000);
_timer.Elapsed += (sender, e) => MailsSent = 0;
_timer.Start();
}
protected override async Task BackgroundProcessing(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
if (MailsSent < MailsSentInMinute)
{
var workItem = await TaskQueue
.DequeueAsync(stoppingToken);
try
{
await workItem(stoppingToken);
MailsSent++;
}
catch (Exception ex)
{
_logger.LogError(ex,
"Error occurred executing {WorkItem}.", nameof(workItem));
}
}
}
}
}
Now your Email Queue service will control the number of emails send per minute.
Upvotes: 0
Reputation: 580
These throttling limits are controlled by the Transport process within Exchange. As such, any protocol (SMTP, EWS, REST, etc...) that you use in O365 will be subject to the same limitation. One option, assuming you want them coming from the same account is to create several accounts, given them SendAs rights to the account you want the emails coming from and then break up the pool of emails to send into separate queues for each service account. I haven't looked at the transport throttling code in a while, but IIRC, it throttles based on authenticated user rather than sender. Of course, be reasonable about it - if you create 5000 service accounts, one for each email, then that would just be silly :) Figure out what SLA you want. Given that you can send 30/min, 5 accounts could do 150/min. That would get you through the list in less than 4 minutes.
Upvotes: 1