Adding an attachment to an email wite a MimeKit BodyBuilder takes 20 seconds on a customer site

195 Views Asked by At

I have a .NET Windows service that sends emails using MimeKit. It creates a BodyBuilder and attaches a PDF file:

builder.Attachments.Add(fileName);

Where 'fileName' is the full path and filename of a PDF file. The file exists, it's 300KB, the service can access it. When I test locally with the file in question the Add() is almost instant. On the customer's server with the deployed service, it takes 20 seconds to add the attachment, meaning that the server that the SmtpClient instance is connected to times out waiting for some action after the connect and auth has happened.

What could cause this huge difference in attaching a small file between dev machine and server?

1

There are 1 best solutions below

1
jstedfast On BEST ANSWER

There are a few possibilities:

  1. Slow disk storage access
  2. Low RAM availability

builder.Attachments.Add() loads the file into a MemoryBlockStream internally, so both of those could be a factor.