Merge pull request #6351 from elsa-workflows/improvement/email-attachment-from-expando
Add support for ExpandoObject attachments in email sending
This commit is contained in:
commit
e995cbfd02
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections;
|
||||
using System.Dynamic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
|
@ -183,6 +184,22 @@ public class SendEmail : Activity
|
|||
else if (emailAttachment.Content is Stream stream)
|
||||
await bodyBuilder.Attachments.AddAsync(fileName, stream, parsedContentType, cancellationToken);
|
||||
|
||||
break;
|
||||
}
|
||||
case ExpandoObject expandoObject:
|
||||
{
|
||||
var dictionary = new Dictionary<string, object>(expandoObject, StringComparer.OrdinalIgnoreCase);
|
||||
var fileName = dictionary.GetValue<string>("FileName") ?? $"Attachment-{++index}";
|
||||
var contentType = dictionary.GetValue<string>("ContentType") ?? "application/binary";
|
||||
var parsedContentType = ContentType.Parse(contentType);
|
||||
var content = dictionary.GetValue<object>("Content");
|
||||
|
||||
if (content is byte[] bytes)
|
||||
bodyBuilder.Attachments.Add(fileName, bytes, parsedContentType);
|
||||
|
||||
else if (content is Stream stream)
|
||||
await bodyBuilder.Attachments.AddAsync(fileName, stream, parsedContentType, cancellationToken);
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
|
|||
Loading…
Reference in a new issue