我有一个具有文件上传控件的页面,在提交表单时,当文件上传控件有文件时,文件通过邮件中的附件发送并且工作正常,但是当文件上传控件没有文件时,ATT00006.dat文件通过电子邮件附件自动发送。
参考网址:http ://nextech.pk/Enquiry.aspx?Enq=cu
提前感谢您的帮助
编辑——代码:
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>	" + 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);