Is it possible to add IFormFile files to email attachments in .net core? I am getting files from angular using formdata.
for (let file of this.files) {
this.formData.append("Files", file.nativeFile);
}
MailMessage mail = new MailMessage();
SmtpClient smtp = new SmtpClient
{
Host = "smtp.sendgrid.net",
Port = 25,
Credentials = new System.Net.NetworkCredential("key", "pass")
};
[HttpPost("[action]")]
public IActionResult UploadFiles(IList<IFormFile> Files)
{
foreach (var file in Files)
{
using (var stream = file.OpenReadStream())
{
var attachment = new Attachment(stream, file.FileName);
mail.Attachments.Add(attachment);
}
}
mail.To.Add("email@hotmail.com");
mail.From = from;
mail.Subject = "Subject";
mail.Body = "test";
mail.IsBodyHtml = true;
smtp.Send(mail);