asp.net中的无效邮件附件 [英] Invalid mail attachment in asp.net

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

问题描述

我正在发送带有附件的邮件.我实现了该解决方案,但是有一个错误; 无效的邮件附件".以下是我的代码.

I am sending mail with attachment. I implemented the solution, but there is one error; "Invalid mail attachment". Following is my code.

if (chkinstant .Checked)
{
   txtto.Visible = true;
   lblto.Visible = true;
   MailMessage msg = new MailMessage();
   msg.From = "nagaswarupa@brihaspathi.com";
   msg.To = txtto.Text;
   msg.Subject = txtsub.Text.Trim();
   msg.Body = txtbody.Text;

   HttpFileCollection hfc = Request.Files;
   for (int z = 0; z < hfc.Count; z++)
   {
       HttpPostedFile hpf = hfc[z];
       if (hpf.ContentLength > 0)
       {
           hpf.SaveAs(Server.MapPath("MyFiles") + "\\" +
             System.IO.Path.GetFileName(hpf.FileName));
           string strfilename = hpf.FileName;
           msg.Attachments.Add(new MailAttachment(strfilename));
           SmtpMail .Send(msg);
           lblmessage.Text = "Your message has been sent.";
       }
   }
   SmtpMail.Send(msg);
   lblmessage.Text = "Your message has been sent.";
}

推荐答案

我认为这与文件类型无关.我可能是权限问题.如果某个文件夹中所有文件的附件均失败,则必须对该文件夹及其上的安全设置(ASPNET应该具有读取权限)进行某些操作.
I don''t think it has something to do with the file type. I can be a permission problem. If the attachment of all files in some folder fails it should have to do something with that folder and the security settings on it (ASPNET should have read rights).


请尝试遵循

Please try following

string FileName = Server.MapPath("MyFiles") + "\\" + Path.GetFileName(hpf.FileName);
msg.Attachments.Add(new MailAttachment(FileName));




谢谢,
Imdadhusen




Thanks,
Imdadhusen


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

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