ATT00006.dat 文件自动附加在邮件附件中
我有一个具有文件上传控件的页面,在提交表单时,当文件上传控件有文件时,文件通过邮件中的附件发送并且工作绝对正常,但是当文件上传控件没有文件时,ATT00006 .dat 文件会通过电子邮件附件自动发送。
参考网址:http://nextech.pk/Enquiry.aspx?Enq=cu
提前感谢您的任何帮助
编辑--代码:
hpf = fup1.PostedFile;
String toEmail = "[email protected]";
String fromEmail = "[email protected]";
MailMessage objMail = new MailMessage(fromEmail, toEmail);
objMail.IsBodyHtml = true;
StringBuilder MailBody = new StringBuilder();
MailBody.Append("<html><head></head><body> <br>");
MailBody.Append("<br>" + "An enquiry is filed <br><br>");
MailBody.Append("<strong><u>Enquirer Information</u></strong>" + "<br><br>");
MailBody.Append("<strong>Contact Name:</strong>	" + txtFirstName.Text + "<br>");
MailBody.Append("<strong>Email:</strong>			 " + txtEmail.Text + "<br>");
MailBody.Append("<strong>Institute:</strong>		 " + txtInstitute.Text + "<br>");
MailBody.Append("<strong>Phone #:</strong>		 " + txtPhone.Text + "<br>");
MailBody.Append("<br><strong>Description:</strong><br>         " + txtEnquiry.Text + "<br>");
if (hpf != null)
{
MailBody.Append("<br>" + "This email also contains an attachment:- <Strong>(" + hpf.FileName + ")</Strong><br>");
}
MailBody.Append("</body></html>");
objMail.Body = MailBody.ToString();
if (hpf != null)
{
System.IO.Stream inputStream = hpf.InputStream;
String fileName = hpf.FileName;
Attachment attach = new Attachment(inputStream, fileName);
objMail.Attachments.Add(attach);
}
SmtpClient SmtpClnt = new SmtpClient();
SmtpClnt.Send(objMail);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不知道你是否得到了这个问题的答案,但我最近详细研究了这个问题。出现此问题的原因是您没有为附件提供明确的名称。除非显式定义名称,否则 ASP.NET 将始终附加为 .DAT。
问题是人们认为 ASP.NET 将使用文件名作为附件名称,但事实并非如此!
在代码中,您应该创建附件的实例,然后使用 FileUpload.FileName 属性显式提供名称:
完整说明
I don't know if you ever got an answer to this, but I've recently studied the problem in detail. The problem occurs because you did not provide an explicit name for the attachment. ASP.NET will always attach as .DAT unless the name is explicitly defined.
The problem is that people assume ASP.NET will use the Filename as the attachment name, which doesn't happen!
In your code, you should create an instance of the attachment, then provide the name explicitly using the FileUpload.FileName property:
A full explanation of ASP.NET attaching .DAT files is available here
这是系统无法理解的附件类型不匹配。请发布您的代码以及当没有文件作为附件时您会做什么。
Its a mis-match in the attachment type that the system doesn't understand. Please post your code and what you do when there is not file as an attachment.
我认为您正在使用的邮件服务器(或邮件服务器使用的防病毒软件)会自动添加此文件。
有问题的文件是否包含任何内容,或者是空的?
I think the mail server you are using (or antivirus software used by the mail server) is automatically adding this file.
Does the file in question contain anything, or is it empty?