Overview From our MVC web app we are sending emails. We send 2,000 each time, once per day.
We send the emails one at a time to Postmark to process and deliver.
The connection with Postmark is via SMTP which is setup in Web.Config:
<mailSettings>
<smtp deliveryMethod="Network" from="[email protected]">
<network host="smtp.postmarkapp.com" port="587" enableSsl="true" defaultCredentials="false" userName="username" password="password" />
</smtp>
</mailSettings>
We're using Postal in our app for email templating, etc.
foreach(var user in users)
{
var email = new Postal.Email;
{
EmailTo = user.Email,
Subject = "Subject",
//other email content
};
//Send email
email.Send();
}
Our web app is on Azure in a Web App service.
The processing and sending is being done in a background method using Hangfire with no automatic retries.
Problem There is a small percentage (exact percentage not known) of recipients that are consistently receiving duplicates or triplicates of these emails each day. We haven't noticed a pattern with the ones receiving more than one (i.e. that they're from the same domain, etc.).
In our code, the email details and content are created in a loop and fired off one at a time. We've added logging in our code to verify that we're really only creating one email to the people receiving duplicate and triplicate emails.
We've talked to Postmark about any ideas they have. They said they didn't think it was them. I've looked in the headers of the emails via the Postmark UI and the duplicates have unique message Id's.
Question Are there things that can happen with the way emails are handled when lots of them are being fired off in short succession using SMTP in an MVC app? Is there a way to log what is actually being sent from the app/server?