When submitting the form, everything in the controller arrives completed, minus the file that is attached. Where is the error?
Controller:
public ActionResult EnviaEmail(string destinatario, string assunto, string mensagem, FileStream arquivo)
{
SmtpClient client = new SmtpClient();
client.Port = 28;
client.Host = "exchange.minhaempresa.local";
client.EnableSsl = true;
client.Timeout = 10000;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("gustavo.r", "123456");
MailMessage mm = new MailMessage("[email protected]", destinatario, assunto, mensagem);
mm.BodyEncoding = UTF8Encoding.UTF8;
mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
mm.Attachments.Add(new Attachment(arquivo, "attachment"));
//mm.Attachments.Add(new Attachment(fileAttachment));
client.Send(mm);
return View();
}
html:
<form id="formulario" action="~/Gerenciamento/EnvioEmail/EnviaEmail" method="post" enctype="multipart/form-data">
<label>Destinatario:</label><input type="text" name="destinatario" /><br />
<label>Assunto:</label><input type="text" name="assunto" /><br />
<label>Mensagem:</label> <textarea name="mensagem" /></textarea><br />
<label>Anexo:</label><input name="arquivo" type="file" />
<button>Enviar</button>
</form>