Update SendEmail with support for sending Streams as attachment
This commit is contained in:
parent
15743c4396
commit
db7534edda
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Reference in a new issue