Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# SMTP服务器不发送带有附件的邮件.NET MVC_C#_Email_Smtp_Email Attachments - Fatal编程技术网

C# SMTP服务器不发送带有附件的邮件.NET MVC

C# SMTP服务器不发送带有附件的邮件.NET MVC,c#,email,smtp,email-attachments,C#,Email,Smtp,Email Attachments,我的问题是,只要我尝试通过内部SMTP服务器发送附件,就会出现错误。一旦连接超过150KB,就会发生错误。SMTP服务器上的限制设置为25MB。 当我在我的开发机器上测试它时,一切正常,但一旦它在实时服务器上,就会出现文件无法打开且无法访问的问题。我没有使用任何文件流 Exception: System.ObjectDisposedException Message: Cannot access a closed file. Source: mscorlib at System.I

我的问题是,只要我尝试通过内部SMTP服务器发送附件,就会出现错误。一旦连接超过150KB,就会发生错误。SMTP服务器上的限制设置为25MB。 当我在我的开发机器上测试它时,一切正常,但一旦它在实时服务器上,就会出现文件无法打开且无法访问的问题。我没有使用任何文件流

    Exception: System.ObjectDisposedException
Message: Cannot access a closed file.
Source: mscorlib
   at System.IO.__Error.FileNotOpen()
   at System.IO.FileStream.Seek(Int64 offset, SeekOrigin origin)
   at System.Web.HttpRawUploadedContent.TempFile.GetBytes(Int32 offset, Int32 length, Byte[] buffer, Int32 bufferOffset)
   at System.Web.HttpRawUploadedContent.CopyBytes(Int32 offset, Byte[] buffer, Int32 bufferOffset, Int32 length)
   at System.Web.HttpInputStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at System.Net.Mime.MimePart.Send(BaseWriter writer, Boolean allowUnicode)
   at System.Net.Mime.MimeMultiPart.Send(BaseWriter writer, Boolean allowUnicode)
   at System.Net.Mail.SmtpClient.Send(MailMessage message)
守则:

        NetworkCredential loginInfo = new NetworkCredential(model.user, model.password);

        SmtpClient smtpClient = new SmtpClient(model.server, int.Parse(model.port));
        smtpClient.EnableSsl = model.ssl;
        smtpClient.UseDefaultCredentials = false;
        smtpClient.Credentials = loginInfo;

        MailMessage mail = new MailMessage();                            
        mail.From = new MailAddress(model.from);   //From Adress
        mail.To.Add(new MailAddress(model.to));    //To Adress
        mail.Subject = model.subject;
        mail.Body = model.body;
        mail.IsBodyHtml = true;  
                
        foreach (var file in model.attachments)
        {
            mail.Attachments.Add(new Attachment(file.InputStream, file.FileName));
        }

        smtpClient.Send(mail);

所以问题出在我的web.config中。 我必须添加“requestLengthDiskThreshold=“512000”参数

<httpRuntime targetFramework="4.7.1" maxRequestLength="512000" requestLengthDiskThreshold="512000" executionTimeout="600" enableKernelOutputCache="false" relaxedUrlToFileSystemMapping="true" requestValidationMode="4.0" enableVersionHeader="false" requestValidationType="Sitecore.Web.RequestValidators.SitecoreBackendRequestValidator, Sitecore.Kernel" />


电子邮件列表上有多少人?您可能需要拆分列表。只需一个接收器