ATT00006.dat 文件自动附加在邮件附件中

发布于 2024-08-04 10:00:56 字数 2354 浏览 3 评论 0 原文

我有一个具有文件上传控件的页面,在提交表单时,当文件上传控件有文件时,文件通过邮件中的附件发送并且工作绝对正常,但是当文件上传控件没有文件时,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>&#09;" + txtFirstName.Text + "<br>");
    MailBody.Append("<strong>Email:</strong>&#09;&#09;&#09; " + txtEmail.Text + "<br>");
    MailBody.Append("<strong>Institute:</strong>&#09;&#09; " + txtInstitute.Text + "<br>");
    MailBody.Append("<strong>Phone #:</strong>&#09;&#09; " + txtPhone.Text + "<br>");

    MailBody.Append("<br><strong>Description:</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; " + 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);

I have a page that have fileupload control, on the submission of the form, when the fileupload control has file, file is sent via attachment in a mail and working absulutly fine, but when the fileupload control does not have file, ATT00006.dat file is automatically sent via email attachment.

Reference URL: http://nextech.pk/Enquiry.aspx?Enq=cu

Advance Thanks for any help

Edit -- Code:

 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

墨小墨 2024-08-11 10:00:56

我不知道你是否得到了这个问题的答案,但我最近详细研究了这个问题。出现此问题的原因是您没有为附件提供明确的名称。除非显式定义名称,否则 ASP.NET 将始终附加为 .DAT。

问题是人们认为 ASP.NET 将使用文件名作为附件名称,但事实并非如此!

在代码中,您应该创建附件的实例,然后使用 FileUpload.FileName 属性显式提供名称:

Dim att As New System.Net.Mail.Attachment(fu.PostedFile.InputStream, System.Net.Mime.MediaTypeNames.Application.Octet) ' use Octet for binary files '
att.Name = fu.FileName ' get the file name and type automatically '
mm.Attachments.Add(att)

完整说明

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:

Dim att As New System.Net.Mail.Attachment(fu.PostedFile.InputStream, System.Net.Mime.MediaTypeNames.Application.Octet) ' use Octet for binary files '
att.Name = fu.FileName ' get the file name and type automatically '
mm.Attachments.Add(att)

A full explanation of ASP.NET attaching .DAT files is available here

执手闯天涯 2024-08-11 10:00:56

这是系统无法理解的附件类型不匹配。请发布您的代码以及当没有文件作为附件时您会做什么。

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.

空气里的味道 2024-08-11 10:00:56

我认为您正在使用的邮件服务器(或邮件服务器使用的防病毒软件)会自动添加此文件。

有问题的文件是否包含任何内容,或者是空的?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文