在asp.net中的邮件附加失败 [英] mail attaching failed in asp.net

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

问题描述

邮件附加失败,我在下面的代码中写了

mail attaching coming failed i wrote below code

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)
  {
    string FileName = Server.MapPath("MyFiles") + "\\" + Path.GetFileName(hpf.FileName);
    msg.Attachments.Add(new MailAttachment(FileName));

    SmtpMail.Send(msg);
    lblmessage.Text = "Your message has been sent.";
  }
}
SmtpMail.Send(msg);
lblmessage.Text = "Your message has been sent.";


但是我变得像错误的邮件附件"D:\ crmproject \ CRMProject \ MyFiles \ exelgridview.txt"之类的错误.我在哪里出错了?


but I''m becoming error like Invalid mail attachment ''D:\crmproject\CRMProject\MyFiles\exelgridview.txt''. Where did I do a mistake?

推荐答案

使用此代码
Use this code
MailAddress SendFrom = new MailAddress("Your Email address");
       MailAddress SendTo = new MailAddress("Your Email address");
       MailAddress MailCC = new MailAddress("Your Email address");
       MailAddress MailBCC = new MailAddress("Your Email address");


       MailMessage MyMessage = new MailMessage(SendFrom, SendTo);
       MyMessage.CC.Add(MailCC);
       MyMessage.Bcc.Add(MailBCC);
       MyMessage.Subject = "Your subject";
       MyMessage.IsBodyHtml=true;
       MyMessage.Body = "Your body";
       Attachment attachFile = new Attachment(path+filename);

       SmtpClient emailClient = new SmtpClient("Your server IP");
       emailClient.Send(MyMessage); :)


希望这对您有帮助!!!!!!!!!


Hope this helps!!!!!


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

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