Question

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 = "test@hotmail.com";
    String fromEmail = "mailer@hotmail.com";
    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);
Was it helpful?

Solution

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.

OTHER TIPS

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

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?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top