I'm not sure about the details of how SmtpDeliveryMethod.SpecifiedPickupDirectory works and what it does for sure, but I suspect that it could just save the message in a directory where the on-premises Exchange server periodically checks the mail for sending.
Assuming a case, you could do something like this:
void SaveToPickupDirectory (MimeMessage message, string pickupDirectory) { do { // Note: this will require that you know where the specified pickup directory is. var path = Path.Combine (pickupDirectory, Guid.NewGuid ().ToString () + ".eml"); if (File.Exists (path)) continue; try { using (var stream = new FileStream (path, FileMode.CreateNew)) { message.WriteTo (stream); return; } } catch (IOException) { // The file may have been created between our File.Exists() check and // our attempt to create the stream. } } while (true); }
The code snippet above uses Guid.NewGuid () as a way to generate a temporary file name, but you can use whatever method you want (for example, you can also use message.MessageId + ".eml" ).
Based on Microsoft referencesource , when SpecifiedPickupDirectory used, they actually also use Guid.NewGuid ().ToString () + ".eml" , so this is probably the way to go.
source share