C#发送带附件邮件
2012-04-11 18:09
483 查看
using System; using System.Collections.Generic; using System.Web; using System.Net.Mail; using System.Text; using System.Configuration; using System.Web.UI; using System.Web.UI.WebControls; public partial class sendmail : System.Web.UI.Page { //带附件发送 public static bool SendMailsf(string fromUser, string fromUserName, string toUser, string toUserName, string cc, string subjectNm, string bodyAll, string fj) { bool ret = false; try { //Attachment objMailAttachment; //创建一个附件对象 //objMailAttachment = new Attachment("d:\\test.txt");//发送邮件的附件 objMailAttachment = new Attachment(fj);//发送邮件的附件 MailMessage mm = new MailMessage(); mm.From = new MailAddress(fromUser, fromUserName, Encoding.UTF8); mm.To.Add(toUser); string[] listc = null; try { if (cc != null && cc != "") { listc = cc.Split(','); for (int i = 0; i < listc.Length; i++) { mm.CC.Add(listc[i].ToString()); } } } catch (Exception list) { throw list; } mm.Attachments.Add(objMailAttachment);//将附件附加到邮件消息对象中 mm.Subject = subjectNm; mm.SubjectEncoding = Encoding.UTF8; mm.Body = bodyAll; mm.BodyEncoding = Encoding.UTF8; mm.IsBodyHtml = true; //mm.Priority = MailPriority.High;//加急邮件! SmtpClient client = new SmtpClient(); client.Credentials = new System.Net.NetworkCredential("帐号", "密码"); client.Host = "主机"; client.Send(mm); ret = true; } catch (Exception ex) { throw ex; } return ret; } }
相关文章推荐
- C# 调用outlook 发送邮件 或添加附件发送
- C# winform发送邮件 带附件
- c#.net 下的邮件发送(含附件)
- C# - MailSender 邮件发送组件源代码 (支持ESMTP, 附件)
- C#发送邮件(附件)类
- C#编程实现发送邮件的方法(可添加附件)
- 【C#工具类】发送邮件(带有图片和附件)
- c# 发送带附件的邮件
- 使用C#编写简单的图形化的可发送附件的邮件客户端程序
- C# 发送邮件(内容中可以插入图片,邮件可以添加附件,163邮箱、QQ邮箱等都可以使用)
- c#net中发送带附件的邮件:
- c#发送带附件的邮件
- C#邮件发送 批量发送邮件 发送邮件嵌入图片 添加附件
- C#发送带附件的邮件
- C#发送邮件小程序(支持群发,附件)
- C#基于SMTP协议和SOCKET通信,实现邮件内容和附件的发送,并可隐藏收件人
- C#发送邮件小程序(支持群发,附件)
- C#发送带附件邮件
- c#发送邮件含附件
- C# 解决 邮件发送Excel附件后,excel处于锁定状态