是否可以将 IFormFile 文件添加到 .net 核心中的电子邮件附件?我正在使用 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);