电子邮件附件不会上传 [英] Email Attachment wont upload

查看:87
本文介绍了电子邮件附件不会上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好亲爱的CPers,

我有一个网络表单,其功能类似于电子邮件撰写邮件并将其发送.我有To,CC,身体区域.除了它们之外,我还有一个复选框可以解决我的问题.当用户选中此复选框时,它应该在特定文件夹下找到一个文件,并将该文件作为附件添加到电子邮件中.此过程在我的计算机上成功运行.但是在生产服务器中,此功能不起作用.这是我的代码:

Hello dear CPers,

I have a web form which functions like a email compose message and send it. I have To,CC, Body area. In addition to them, I have a checkbox where I am having my problem. When user checks this checkbox it supposed to find a file under a specific folder and add a file to the email as an attachment. This process is successfully functioning in my computer. But in the production server this functionality is not working. Here is my code:

MailMessage message = new MailMessage();
                message.IsBodyHtml = true;
                string body = txtTemplate.Text;
                message.Body = body;
                message.Subject = txtEmailSubject.Text;
                message.To.Add(new System.Net.Mail.MailAddress(txtRecipient.Text));
                if (txtCCEmail.Text != "")
                {
                    message.CC.Add(new System.Net.Mail.MailAddress(txtCCEmail.Text));
                }
                message.From = new MailAddress("mail@blabla.com");
                if (chkAttachment.Checked)
                {
                    string shippingLabelPath = HttpContext.Current.Server.MapPath(RMAConfig.LabelPath + "Shipping Label[" + EmailVariables[0].ToString() + "].pdf");
                    string returndocPath = HttpContext.Current.Server.MapPath(RMAConfig.PDFPath + "Return Documentation [ " + EmailVariables[0].ToString() + " ].pdf");
                    if (File.Exists(shippingLabelPath))
                    {
                        Attachment attachedShipping = new Attachment(shippingLabelPath);
                        attachedShipping.ContentDisposition.FileName = "Shipping Label.pdf";
                        message.Attachments.Add(attachedShipping);
                    }
                    if (File.Exists(returndocPath))
                    {
                        Attachment attachedRReturnDoc = new Attachment(returndocPath);
                        attachedRReturnDoc.ContentDisposition.FileName = "Return Documentation.pdf";
                        message.Attachments.Add(attachedRReturnDoc);
                    }
                }
                System.Net.Mail.SmtpClient server = new System.Net.Mail.SmtpClient("mail.blabla.com");
                server.Credentials = new System.Net.NetworkCredential("email@email.com", "*******");
                server.Send(message);              



我确保文件存在于文件夹中,并且它们肯定在那里.但是它们并没有连接到生产服务器中.有什么我想念的吗?

谢谢大家



I have made sure the files exists in the folder and they certainly are there. But they are not getting attached in production server. Is there something I am missing?

Thank you all

推荐答案

在发送带有附件的电子邮件时需要考虑的两件事.
1.将要附加的文件必须具有读取权限.您已经与Naerling讨论过了.
2.必须对照IIS工作进程允许的实际大小检查文件的大小.可以从Web应用程序的web.config文件中进行设置.
Two things that you need to consider while sending an email with attachment.
1. The file that is going to be attached has to have read permission. You already discussed with Naerling.
2. The size of the file has to checked against the actual size permitted to process by IIS worker process. This can be set from the web.config file of your web application.
<!-- Execute maximum 100MB file size and upload execution time out 15 minutes-->
    <httpRuntime maxRequestLength="102400" executionTimeout="5400"/>


希望对您有帮助.


Hope this will help you well.


这篇关于电子邮件附件不会上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆