asp.net,2.0发送和接收邮件总结x.docx

上传人:w**** 文档编号:62234959 上传时间:2022-11-22 格式:DOCX 页数:13 大小:13.68KB
返回 下载 相关 举报
asp.net,2.0发送和接收邮件总结x.docx_第1页
第1页 / 共13页
asp.net,2.0发送和接收邮件总结x.docx_第2页
第2页 / 共13页
点击查看更多>>
资源描述

《asp.net,2.0发送和接收邮件总结x.docx》由会员分享,可在线阅读,更多相关《asp.net,2.0发送和接收邮件总结x.docx(13页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、,2.0发送和接收邮件总结x 2.0 发送和接收邮件总结 总结:.用 2.0 发送邮件特别的便利,只须要用 using System.Net.Mail 命名空间下的类就可以完成发送邮件的功能,发送邮件的服务器可以有以下几种状况: 1.本地的 smtp 服务器 2.网络上的 smtp 服务器( 等) 以下是我测试发送邮件的范例,基本上都考虑到的全部的状况,假如还有什么没有考虑到的请给我留言,我接续完善其功能. 1.新建一网站名字叫 SentEmailText. 2.添加一个新的页面 default.aspx 代码如下: <form id=Form1 runat=server method=

2、post><div id=content><div id=msg> title>Send Email Test</div> <div id=msg_prompt></div> <asp:ValidationSummary id=msg_alarm runat=server></asp:ValidationSummary> </div> <div id=form><div> <label for=SmtpServerText>Sever name:<

3、;/label> <input type=textid=SmtpServerText name=SmtpServerText runat=server /> </div><div> <label for=SmtpServerPort>Sever Port:</label> <input type=text id=SmtpServerPortname=SmtpServerPort runat=server /> </div><div> <label for=UserName>User

4、 Name:</label> <input type=textname=UserName id=UserName runat=server /> </div><div> <label for=Pwd>Pwd:</label> <input type=textname=Pwd runat=server id=Pwd /> </div><div> <label for=FromAddress>From Address:</label> <input type=t

5、extname=FromAddress runat=server id=FromAddress /></div><div> <label for=SendAddress>Send Address:</label> <input type=textname=SendAddress runat=server id=SendAddress /> </div><div> <label for=attachment>Attachment:</label> <input type=fil

6、e runat=server name=attachment id=attachment /> </div><div> <label for=txtSubject>Email Subject:</label> <input type=textname=txtSubject runat=server id=txtSubject /> </div> <div> <label for=txtBody>Email Body:</label> <textarea name=txtBod

7、y runat=server rows=10 cols=50 id=txtBody></textarea> </div> <div> nbsp; nbsp; nbsp; nbsp; nbsp; nbsp; nbsp; nbsp; nbsp; nbsp; nbsp; <input type=submit value=Send Email class=prim id=btnSend runat=server onserverclick=btnSend_ServerClick /> </div> </div></di

8、v> </form> 3.新建一个 style 的文件夹,添加样式页面,主要功能是表单的对齐样式,比较通用的设置(见附件) 4.添加一个 mail 的类文件,留意用于发送邮件考虑的几种状况(见附件) ; Text;Mail; Net.Sockets; using System.IO; public class Mail Custom var#region Custom var User; Pwd; string _Host; private int _Port; #endregion Property#region Property public int Port get r

9、eturn _Port; set _Port = value; public string User get return _User; set _User = value; public string Pwd get return _Pwd; set _Pwd = value; public string Host get return _Host; set _Host = value; #endregionOverLoad#region OverLoad public Mail(string user, string pwd,string host,int port) /other smt

10、p server including username and pwd User = user; Pwd = pwd; Host = host; this._Port = port; public Mail(string host,int port) /other smtp server but username and pwd Port = port; this._Host = host; public Mail() /local smtp server and port=25 Port = 25; this._Host = 127.0.0.1; #endregionSend Emial i

11、ncluding groups and attachment#region Send Emial including groups and attachment /*/ <summary> Sent emails including attachment /summary> User>From Address</param> toMail>To Address</param> subject>The subject of Email</param> body>The body of Email</param&g

12、t; ishtml>Html Or Text</param> priority>The priority of Email</param> / <param name=filenames>the attachment of email(optional)</param> public void SendMailWithAttachment(string toUser,string toMail, string subject, string body,bool ishtml,MailPriority priority,params s

13、tring filenames) System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(toUser,toMail,subject,body); BodyEncoding = Encoding.UTF8; Priority = priority; msg.IsBodyHtml = ishtml ; if (filenames != null) foreach (string s in filenames) msg.Attachments.Add(new Attachment(s); System.Net.Mail.S

14、mtpClient sc = new SmtpClient(Host, Port); EnableSsl = false; Timeout = 3600000; UseDefaultCredentials = false; Credentials = new System.Net.NetworkCredential(_User, _Pwd); sc.DeliveryMethod = SmtpDeliveryMethod.Network; try sc.Send(msg); catch (Exception e) throw e; /*/ <summary> Sent Email i

15、ncluding groups and attachment /summary> User>From Address</param> toMail>To Address</param> subject>The subject of Email</param> body>The body of Email</param> ishtml>Html Or Text</param> priority>The priority of Email</param> / <param nam

16、e=filenames>The attachment of Email(optional)</param> public void SendMailWithGroupWithAttachment(string toUser,string toMail, string subject, string body,bool ishtml,MailPriority priority,params string filenames) string toMails = toMail.Split(;); System.Net.Mail.MailMessage msg = new Syste

17、m.Net.Mail.MailMessage(); msg.From=new MailAddress(toUser ); foreach (string s in toMails) msg.To.Add(s); Subject = subject; = by; BodyEncoding = Encoding.UTF8; msg.Priority = priority;msg.IsBodyHtml = ishtml; if (filenames != null) foreach (string s in filenames) msg.Attachments.Add(new Attachment(

18、s); System.Net.Mail.SmtpClient sc = new SmtpClient(Host,Port); EnableSsl = false; Timeout = 3600000; UseDefaultCredentials = false; Credentials = new System.Net.NetworkCredential(_User, _Pwd); sc.DeliveryMethod = SmtpDeliveryMethod.Network; try sc.Send(msg); catch (Exception e) throw e; #endregion/*

19、/ <summary> Received Email / </summary> public void ReseiveMail() string ServerHost = pop3.+this._Host ; TcpClient tcp = new TcpClient(ServerHost, 110); NetworkStream ns = tcp.GetStream(); Reader sr = new StreamRead); StreamWriter sw = new StreamWriter(ns);5.页面调用方式参见附件 6.附件下载附件(源代码下载) 付出最大努力,追求最高成就。

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 应用文书 > 工作计划

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁