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:
Sipke Schoorstra 2025-01-29 11:45:36 +01:00 committed by GitHub
commit e995cbfd02
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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: