Skip to content

Commit

Permalink
Refactor mail attachments (#7521)
Browse files Browse the repository at this point in the history
  • Loading branch information
deanmarcussen authored Nov 5, 2020
1 parent 84ac3aa commit 772652e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,13 @@ private MimeMessage FromMailMessage(MailMessage message)
body.TextBody = message.Body;
}

if (message.Attachments != null)
foreach (var attachment in message.Attachments)
{
foreach (var attachment in message.Attachments)
// Stream must not be null, otherwise it would try to get the filesystem path
if (attachment.Stream != null)
{
// Stream must not be null, otherwise it would try to get the filesystem path
if (attachment.Stream != null)
{
body.Attachments.Add(attachment.Filename, attachment.Stream);
}
}
body.Attachments.Add(attachment.Filename, attachment.Stream);
}
}

mimeMessage.Body = body.ToMessageBody();
Expand Down
4 changes: 2 additions & 2 deletions src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public class MailMessage
public bool IsBodyHtml { get; set; }

/// <summary>
/// Gets or sets the message attachments.
/// The collection of message attachments.
/// </summary>
public IEnumerable<MailMessageAttachment> Attachments { get; set; }
public List<MailMessageAttachment> Attachments { get; } = new List<MailMessageAttachment>();
}
}

0 comments on commit 772652e

Please sign in to comment.