在asp.net中发送的邮件中,无法打开附件. [英] In Mail sending in asp.net, Attached file can not be open .

查看:75
本文介绍了在asp.net中发送的邮件中,无法打开附件.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的asp.net网站上

在邮件发送"中,无法打开附件文件.邮件可以成功发送,然后消息可以显示在要发送的帐户中,但附件无法打开.

所有文件都显示我的附件.然后它就无法打开.

我发送邮件的代码是
....................................

In my asp.net website

In Mail sending , Attached file can not be open .the mail can send successfully,Then message can show in account to send but attachments can not be open.

all files show my attachment.then it can''t be open.

my code to send mail is
..........................

SmtpClient client = new SmtpClient();
           MailMessage message = new MailMessage();

           DataSet ds = new DataSet();
           if (txtemail.Text != "")
           {
               ds.ReadXml(Server.MapPath("~/Admin/xml/feedbackmail.xml"));
               string fromAddress = ds.Tables[0].Rows[0][0].ToString();
               message.From = new MailAddress(fromAddress);
               string ToAddress = txtemail.Text.Trim();
               message.To.Add(new MailAddress(ToAddress));// = address(ToAddress);
               //  mail1.To = txtfatherMail.Text.Trim();  mail.From = new MailAddress(txtFrom.Text);
               //   mail1.To = txtMotherId.Text.Trim();
               if (FuAttachment.PostedFile != null)
               {
                   /* Get a reference to PostedFile object */
                   HttpPostedFile attFile = FuAttachment.PostedFile;
                   /* Get size of the file */
                   int attachFileLength = attFile.ContentLength;
                   /* Make sure the size of the file is > 0  */
                   if (attachFileLength > 0)
                   {
                       /* Get the file name */
                       string strFileName = Path.GetFileName(FuAttachment.PostedFile.FileName);
                       /* Save the file on the server */
                       FuAttachment.PostedFile.SaveAs(Server.MapPath(strFileName));
                       /* Create the email attachment with the uploaded file */
                       // MailAttachment attach = new MailAttachment(Server.MapPath(strFileName));
                       /* Attach the newly created email attachment */
                       //  message.Attachments.Add(attach);
                       MemoryStream stream2 = new MemoryStream(new byte[64000]);
                       Attachment attachment2 = new Attachment(stream2, "my attachment");
                       message.Attachments.Add(attachment2);
                       /* Store the attach filename so we can delete it later */
                       string attach1 = strFileName;
                   }
               }

               message.Body = "Sender : " + txtemail.Text + "\n" + "Name : " + txtname.Text + "\n" + "\n" + "Sub:" + txtsubject.Text + "\n" + "Body :" + txtmsg.Text;
               client.Send(message);


           }




请帮助我




please help me

推荐答案

我对出现问题并不感到惊讶:您所附加的只是一个已创建但未定义的字节流:

I''m not that surprised there are problems: all you attach is an created-but-not-defined stream of bytes:

MemoryStream stream2 = new MemoryStream(new byte[64000]);
Attachment attachment2 = new Attachment(stream2, "my attachment");
message.Attachments.Add(attachment2);

我认为您需要查看附加的实际文件内容.
这里有一个常规程序可以完成所有这些工作,我知道它可以工作! 使用C#发送带有或不带有附件的电子邮件:通用例程. [ ^ ]

I think you need to look at attaching the actual file content instead.
There is a general routine here that does all that, and I know it works! Sending an Email in C# with or without attachments: generic routine.[^]


这篇关于在asp.net中发送的邮件中,无法打开附件.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆