Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/Senders/FluentEmail.MailKit/MailKitSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ public async Task<SendResponse> SendAsync(IFluentEmail email, CancellationToken?
{
if (_smtpClientOptions.UsePickupDirectory)
{
await this.SaveToPickupDirectory(message, _smtpClientOptions.MailPickupDirectory);
var messageId = await this.SaveToPickupDirectory(message, _smtpClientOptions.MailPickupDirectory);
response.MessageId = messageId;
return response;
}

Expand Down Expand Up @@ -156,20 +157,24 @@ await client.ConnectAsync(
/// </summary>
/// <param name="message">Message to save for pickup.</param>
/// <param name="pickupDirectory">Pickup directory.</param>
private async Task SaveToPickupDirectory(MimeMessage message, string pickupDirectory)
private async Task<string> SaveToPickupDirectory(MimeMessage message, string pickupDirectory)
{
// Note: this will require that you know where the specified pickup directory is.
var path = Path.Combine(pickupDirectory, Guid.NewGuid().ToString() + ".eml");
var messageId = Guid.NewGuid().ToString();
var path = Path.Combine(pickupDirectory, messageId + ".eml");

if (File.Exists(path))
return;
return null;

try
{
//create the directory since it might not exist
Directory.CreateDirectory(pickupDirectory);

using (var stream = new FileStream(path, FileMode.CreateNew))
{
await message.WriteToAsync(stream);
return;
return messageId;
}
}
catch (IOException)
Expand Down