ASP.NET邮件附件不包含数据 [英] ASP.NET mail attachment does not contain data
问题描述
我使用ASP.NET 3.5和C#开发的服务支持Web应用程序。
我发送电子邮件当用户递交的投诉管理员。
我的问题是,当带有附件邮件(WORD,EXCEL,JPG,BMP等)
由附件不包含任何数据的用户发送给管理员。
下面是我用code样品:</ P>
毫米MAILMESSAGE新= MAILMESSAGE();
mm.To.Add(mail1@abcd.com);
mm.From =新的MailAddress(web@abcd.com);如果(FileUpload1.HasFile)///检查,如果邮件附件有
{
mm.Attachments.Add(新附件(FileUpload1.PostedFile.InputStream,ileUpload1.FileName));
}mm.body =测试信息; mm.IsBodyHtml = TRUE; // neceessary凭据在web.config文件中指定 SmtpClient SS =新SmtpClient(); ss.Send(毫米);
要发送带有附件的邮件,您必须首先将文件从服务器上的fileuploader保存,然后你可以发送邮件作为附件。在这里现在的问题是,你是直接试图将文件从FileUpload控件发送的邮件。
一旦邮件有附件发送,那么你就可以从服务器上删除保存的文件。
I am using ASP.NET 3.5 and C# for developing a web application on helpdesk. I am send email to the admin when user lodges a complaint.
My issue is when the mail with attachment(word,excel,jpg,bmp etc) is sent to admin by the user the attachment contains no data.
Here is the code sample I used:
MailMessage mm = new MailMessage();
mm.To.Add(mail1@abcd.com);
mm.From = new MailAddress("web@abcd.com");
if (FileUpload1.HasFile) /// for checking if mail has attachment
{
mm.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, ileUpload1.FileName));
}
mm.body="Test Message";
mm.IsBodyHtml = true;
//neceessary credentials are specified in web.config file
SmtpClient ss = new SmtpClient();
ss.Send(mm);
To send the mail with attachment, you must first save the file from the fileuploader on your server and then you can send it in mail as an attachment. The current problem over here is, you are directly trying to send the file in the mail from fileupload control.
Once the mail is sent with attachment, then you can delete the saved file from your server.
这篇关于ASP.NET邮件附件不包含数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!