c# 发送邮件(附加文件)
2014-04-16 13:37
260 查看
#region 发送邮件 /// <summary> /// 发送邮件 /// </summary> /// <param name="email"></param> /// <param name="emailMix"></param> protected Boolean SendEmail(string username, string email, string emailMix)//用户名,邮箱,标题 { string UrlEmailMix = System.Web.HttpUtility.UrlEncode(emailMix); string strSmtpServer = SysConfig.StrSmtpServer; string strFrom = SysConfig.StrFrom;//发送方帐号 string strFromPass = SysConfig.StrFromPass;//密码 string strto = email; string strSubject = SysConfig.StrSubject; string url = HttpContext.Current.Request.Url.Authority; //string lowerUrl = url.ToLower(); string filePath = "Http://" + url + SysConfig.ApplicationPath + ""; string strBody = "内容"; if (SendSMTPEMail(strSmtpServer, strFrom, strFromPass, strto, strSubject, strBody)) { return true; } else { return false; } } #endregion 发送取回密码邮件 #region 发送邮件接口 /// <summary> /// 发送邮件接口 /// </summary> /// <param name="strSmtpServer">邮件服务器,例如:mail.mycompany.com</param> /// <param name="strFrom">用来发送邮件的email,例如:you@yourcompany.com</param> /// <param name="strFromPass">用来发送邮件的rmail密码</param> /// <param name="strto">发送地址email</param> /// <param name="strSubject">邮件标题</param> /// <param name="strBody">邮件内容</param> protected Boolean SendSMTPEMail(string strSmtpServer, string strFrom, string strFromPass, string strto, string strSubject, string strBody) { // mail.To = "me@mycompany.com"; //mail.From = "you@yourcompany.com"; //SmtpMail.SmtpServer = "mail.mycompany.com"; try { System.Net.Mail.SmtpClient client = new SmtpClient(strSmtpServer); client.UseDefaultCredentials = false; client.Credentials = new System.Net.NetworkCredential(strFrom, strFromPass); client.DeliveryMethod = SmtpDeliveryMethod.Network; System.Net.Mail.MailMessage message = new MailMessage(strFrom, strto, strSubject, strBody); message.BodyEncoding = System.Text.Encoding.UTF8; message.IsBodyHtml = true; string ServerFileName = Server.MapPath("../ExcelFile/" + filename + "");//文件路径 message.Attachments.Add(new Attachment(ServerFileName)); client.Send(message); } catch (Exception er) { return false; } return true; } #endregion 发送邮件接口
相关文章推荐
- 装饰者模式的学习(c#) EF SaveChanges() 报错(转载) C# 四舍五入 保留两位小数(转载) DataGridView样式生成器使用说明 MSSQL如何将查询结果拼接成字符串 快递查询 C# 通过smtp直接发送邮件 C# 带参访问接口,WebClient方式 C# 发送手机短信 文件 日志 写入 与读取
- c#邮件带附件发送成功后附件文件不能及时删除
- c#邮件带附件发送成功后附件文件不能及时删除
- C# 邮件发送接收
- c#之 简单stmp/pop邮件服务(一)-------发送邮件
- 通过C#发送自定义的html格式邮件
- C#发送邮件
- C#通过SMTP发送邮件
- C#发送邮件
- c#邮件发送的实现
- C# 发送邮件的例子
- [导入]C#使用CDO发送邮件
- 使用C#模拟Outlook发送邮件,代码编译报错
- c#中使用自带的邮件发送组件发送邮件的函数
- C#邮件发送 批量发送邮件 发送邮件嵌入图片 添加附件
- C#发送邮件三种方法,Localhost,SMTP,SSL-SMTP
- 老话题之C#写邮件发送
- c# smtp发送邮件
- C#发送邮件程序 及测试邮件服务器
- C#发送邮件时在正文中插入图片(邮件中直接包含图片)