获取电子邮件附件 umbraco 的文件上传

Get file upload for email attachment umbraco

我正在创建一个只有一种形式的简单页面。它的代码如下:

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@using System.Net;
@using System.Net.Mail;
@{
    if(IsPost)
    {
       //Way 1: to get attachment
        var fileSavePath = "";
        var uploadedFile = Request.Files[0];//Here not getting file name
        var fileName = Path.GetFileName(uploadedFile.FileName);
        fileSavePath = Server.MapPath("~/media/" + fileName);
        uploadedFile.SaveAs(fileSavePath);
        FileInfo info = new FileInfo(fileSavePath);
        string[] ext = fileName.Split('.');

        //Way 2 :
        var a = Request["fluld"];//Getting file name only
        var b = Request.Files;//Getting null here

        string d = Path.GetFullPath(Request["fluld"]);
        string c = string.Empty;

        try
        {
            MailMessage mail = new MailMessage();
            SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

            mail.From = new MailAddress("xyz@gmail.com");
            mail.To.Add("xyz@gmail.com");
            mail.Subject = "Test Mail";
            mail.Body = "This is for testing SMTP mail from GMAIL";

            System.Net.Mail.Attachment attachment;
            attachment = new System.Net.Mail.Attachment("filepath");
            mail.Attachments.Add(attachment);

            SmtpServer.Port = 587;
            SmtpServer.Credentials = new System.Net.NetworkCredential("xyz@gmail.com", "******");
            SmtpServer.EnableSsl = true;

            //SmtpServer.Send(mail);
            //MessageBox.Show("mail Send");
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message.ToString());
        }
    }
}
<form method="post">
    <input type="file" name="fluld" id="fluld" />
    <input type="submit" value="Sub"/>
</form>

我无法通过此 Request.Files 获取电子邮件附件文件。帮我解决这个问题。我需要补充什么吗?此代码在 umbraco 模板中。

谢谢

迪帕

您的表单必须是 'multipart/form-data'

<form enctype="multipart/form-data" method="post">
    <input type="file" name="fluld" id="fluld" />
    <input type="submit" value="Sub"/>
</form>