Update SendEmail with support for sending Streams as attachment

This commit is contained in:
Sipke Schoorstra 2021-07-30 20:17:36 +02:00
parent 15743c4396
commit db7534edda
2 changed files with 9 additions and 2 deletions

View file

@ -1,5 +1,5 @@
// ReSharper disable once CheckNamespace
namespace Elsa.Activities.Email
{
public record EmailAttachment(byte[] Content, string? FileName, string? ContentType);
public record EmailAttachment(object Content, string? FileName, string? ContentType);
}

View file

@ -136,7 +136,14 @@ namespace Elsa.Activities.Email
{
var fileName = emailAttachment.FileName ?? $"Attachment-{++index}";
var contentType = emailAttachment.ContentType ?? "application/binary";
bodyBuilder.Attachments.Add(fileName, emailAttachment.Content, ContentType.Parse(contentType));
var parsedContentType = ContentType.Parse(contentType);
if(emailAttachment.Content is byte[] bytes)
bodyBuilder.Attachments.Add(fileName, bytes, parsedContentType);
else if(emailAttachment.Content is Stream stream)
await bodyBuilder.Attachments.AddAsync(fileName, stream, parsedContentType, cancellationToken);
break;
}
default: