说三道四技术文摘-感悟人生的经典句子
说三道四 > 文档快照

SMTP/POP3收发邮件的C#类库SmtPop.Net

HTML文档下载 WORD文档下载 PDF文档下载
SmtPop.net是一个C#类库,使你的代码能够处理SMTP和POP3服务。

 

SmtPop.net是一个C#类库,使你的代码能够处理SMTP和POP3服务。

 

特点:

 

(1)电子邮件发送到SMTP服务器。

(2)从POP3服务器阅读电子邮件

 

MimeMessage类支持

 

(1)支持抄送、密件抄送

(2)“文字”,“援引打印”和“BASE64”格式

(3)多个附件

(4)支持本地操作系统的所有字符集,以及Unicode UTF8

(5)所有标准的MIME头

(6)非标准头

 

例子

 

用SmtPop发送一个简单的电子邮件

 

// build the message	MimeMessage msg = new MimeMessage ();	string body = "This is a simple message for test";	string subject = "A simple message for test";	// build addresses list 	msg.AddressFrom.Add (new MailAddress ("toto <toto@toto.com>")); 	msg.AddressTo.Add (new MailAddress (TestConstant.toadr));	// Save To and From header	msg.SaveAdr ();		// build subject and body 	msg.SetSubject (subject, MimeTransferEncoding.Ascii7Bit);	msg.SetBody (body, MimeTransferEncoding.Ascii7Bit, MimeTextContentType.TextPlain);		// send the message 	SMTPClient smtp = new SMTPClient (TestConstant.host, TestConstant.portsmtp); 	smtp.Open (); 	smtp.SendMail (msg); 	smtp.Close ();

从POP3服务器读取EMAIL

 

// connect to pop server	SmtPop.POP3Client pop = new SmtPop.POP3Client ();  	pop.Open ("localhost", "110", "mylogin", "mypasword");     	// get messages list from pop server	SmtPop.POPMessageId[] messages = pop.GetMailList ();		  	if (messages != null) 	{  		// Walk attachment list	  	foreach (SmtPop.POPMessageId id in messages)  		{		  	SmtPop.POPReader reader = pop.GetMailReader (id.Id);  			SmtPop.MimeMessage msg = new SmtPop.MimeMessage ();       			// read message		  	msg.Read (reader);		  	if (msg.Attachments != null)  			{  				// do something with first attachment				SmtPop.MimeAttachment attach = msg.Attachments[0];  				if (attach.Filename == "data")		  		{  					// read data from attachment			  		Byte[] b = Convert.FromBase64String (attach.Body);  					    					System.IO.MemoryStream mem = new System.IO.MemoryStream (b, false);		  			BinaryFormatter f = new BinaryFormatter ();					DataClass data = (DataClass) f.Deserialize (mem); 					mem.Close();				}						  		  			  								//delete message				pop.Dele (id.Id);			  	}  			}  		}	}			pop.Quit ();

 

下载完整源代码:http://www.okbase.net/file/item/2996

 

 

备案号:鲁ICP备13029499号-2 说三道四 www.s3d4.cn 说三道四技术文摘