I have this in my Controller, and when recieve message the attachment don't have an extension and doesn't know how to open. What to do in this code:
public async Task<ActionResult> Contact(EmailFormModel model)
{
if (ModelState.IsValid)
{
var body = "<p>Email From: {0} ({1})</p><p>Message:</p><p>{2}</p>";
var message = new MailMessage();
message.To.Add(model.FromEmail);
message.Subject = "Your email subject";
message.Body = string.Format(body, model.FromName, model.FromEmail, model.Message);
message.IsBodyHtml = true;
string base64 = model.newImageData;
byte[] imagebytes = Convert.FromBase64String(base64);
message.Attachments.Add(new Attachment(new MemoryStream(imagebytes,0,imagebytes.Length), "Image1"));
using (var smtp = new SmtpClient())
{
await smtp.SendMailAsync(message);
return RedirectToAction("Sent");
}
}
return View(model);
}