Extract files from IFormFile to stream

I am using the Upload Control to get files for email attachments. I think I am pretty close to making it work, but I still have issues accessing IFormFile. Could someone please look at the following code and give me some pointers on how to use IFormFile in this context.

   private async Task SendEmail(List<IFormFile> files)
    {
        try
        {
            // create email message
            var email = new MimeMessage();
            email.From.Add(MailboxAddress.Parse(sender));
            email.To.Add(MailboxAddress.Parse(receiver));
            email.Subject = emailsubject;
            var multipart = new Multipart("mixed");
            multipart.Add(new TextPart(TextFormat.Html) { Text = emailMessage });
            foreach (var attachment in files)
            {
                var content = new MemoryStream();
                attachment.CopyTo(content);
                content.Position = 0;

                var contentType = ContentType.Parse(attachment.ContentType);
                var part = new MimePart(contentType.MimeType)
                {
                    FileName = Path.GetFileName(attachment.FileName),
                    ContentTransferEncoding = ContentEncoding.Base64,
                    Content = new MimeContent(content),
                };

                multipart.Add(part);
            }

            email.Body = multipart;
            //email.Body = new TextPart(TextFormat.Html) { Text = emailMessage};
            // send email
            using var smtp = new SmtpClient();
            smtp.Connect(outgoingServer, outgoingPort, SecureSocketOptions.Auto);
            smtp.Authenticate(userName, userPassword);
            smtp.Send(email);
            smtp.Disconnect(true);
        }
        catch (Exception ex)
        {
            NotificationService.Notify(NotificationSeverity.Error, "Send Email Error!", ex.Message, 7000);
        }
    }
}


Thanks for any help on this

Hi @daveg1466,

You can't use IFormFile in a Blazor component. You can only use it in a controller class. This is how IFormFile works and isn't related to Radzen.

Here is an indepth tutorial that shows how to send emails with attachments using ASP.NET Core: How to Send an Email in ASP.NET Core - Code Maze