CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
IBM Rational 系统开发最佳实践工具包 WebSphere MQ 最佳实践 TOP 15
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  C#

关于ssl,smtp

楼主Marg(三月的雪)2006-03-09 16:35:03 在 .NET技术 / C# 提问

我想用smtp协议发mail,可不知道怎么用c#建立一个ssl的Socket。  
  问题点数:100、回复次数:9Top

1 楼jiezhi(风满袖)回复于 2006-03-09 16:40:39 得分 90

参考:  
  http://www.mentalis.org/soft/projects/ssocket/Top

2 楼Marg(三月的雪)回复于 2006-03-09 16:48:32 得分 0

公司除了csdn什么都上不去,麻烦贴下,谢谢Top

3 楼lovvver(ElephantTalk.Bright)回复于 2006-03-09 16:51:45 得分 10

参考一下:  
  http://systemwebmail.com/  
  Top

4 楼missQJM(......)回复于 2006-03-09 16:52:53 得分 0

够狠  
  只能上CSDNTop

5 楼lovvver(ElephantTalk.Bright)回复于 2006-03-09 16:54:48 得分 0

1,SmtpMail:  
  Using   System.Web.Mail;   Public   void   sendMail    
  ()   {try   {System.Web.Mail.MailMessage   myMail=new   MailMessage   ();    
  MyMail.From   =   "myaccount@test.com";   MyMail.To   =    
  "myaccount@test.com";   MyMail.Subject   =   "MailTest";    
  MyMail.Priority   =   MailPriority.Low;   MyMail.BodyFormat   =    
  MailFormat.Text;   MyMail.Body   =   "Test";    
  SmtpMail.SmtpServer=   "smarthost";   //your   smtp   server   here    
  SmtpMail.Send   (myMail);   }   catch   (Exception   e)   {throw   e;    
  }}  
   
   
  2.CDO:  
  Public   void   CDOsendMail   ()   {try   {CDO.Message   oMsg    
  =   new   CDO.Message   ();   OMsg.From   =   "myaccount@test.com";    
  OMsg.To   =   "myaccount@test.com";   OMsg.Subject   =   "MailTest";  
  OMsg.HTMLBody   =   "<html><body>Test</body></html>";    
  CDO.IConfiguration   iConfg   =   oMsg.Configuration;    
  ADODB.Fields   oFields   =   iConfg.Fields;   OFields   [    
  "http://schemas.microsoft.com/cdo/configuration/sendusing"   ]   Value=2;    
  OFields   [    
  "http://schemas.microsoft.com/cdo/configuration/sendemailaddress"   ]    
  Value=   "myaccount@test.com";   //sender   mail   oFields   [    
  "http://schemas.microsoft.com/cdo/configuration/smtpaccountname"   ]    
  Value=   "myaccount@test.com";   //email   account   oFields   [    
  "http://schemas.microsoft.com/cdo/configuration/sendusername"   ]   Value=  
  "username";   OFields   [    
  "http://schemas.microsoft.com/cdo/configuration/sendpassword"   ]   Value=  
  "password";   OFields   [    
  "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"   ]    
  Value=1;   //value=0   (does   not   need   to   confirm)   //value=1   on    
  behalf   of   the   Anonymous   confirmation   way   (to   use   basic   on   behalf   of    
  the   Basic   confirmation   way   (clear-text)   authentication.   //The    
  configuration   sendusername/sendpassword   or   postusername/postpassword    
  fields   are   used   to   specify   credentials.)   //Value=2   represents    
  the   NTLM   confirmation   way   (Secure   Password   Authentication   in   Microsoft  
  Outlook   Express)   oFields   [    
  "http://schemas.microsoft.com/cdo/configuration/languagecode"   ]    
  Value=0x0804;   OFields   [    
  "http://schemas.microsoft.com/cdo/configuration/smtpserver"   ]   Value=    
  "smtp.21cn.com";   OFields.Update   ();   OMsg.BodyPart.Charset=  
  "gb2312";   OMsg.HTMLBodyPart.Charset=   "gb2312";   OMsg.Send    
  ();   OMsg   =   null;   }   catch   (Exception   e)   {throw   e;   }}  
   
   
  3,Socket:  
  Public   void   SendMail   (MailMessage   msg)   {NetworkStream    
  nwstream   =   GetConnection   ();   WriteToStream   (ref   nwstream,   "EHLO"  
  +   smtpHost   +   "\r\n");   String   welcomeMsg   =   ReadFromStream   (ref    
  nwstream);   //   implement   HELO   command   if   EHLO   is   unrecognized.   if  
  (IsUnknownCommand   (welcomeMsg))   {WriteToStream   (ref   nwstream,   "HELO"   +  
  smtpHost   +   "\r\n");   }   CheckForError   (welcomeMsg,    
  ReplyConstants.OK);   //   Authentication   is   used   if   the   u/p   are    
  supplied   AuthLogin   (ref   nwstream);   WriteToStream   (ref   nwstream,    
  "MAIL   FROM:   <   "+   msg.From.Address   +"   >\r\n");    
  CheckForError   (ReadFromStream   (ref   nwstream),    
  ReplyConstants.OK);   SendRecipientList   (ref   nwstream,   msg.To);    
  SendRecipientList   (ref   nwstream,   msg.CC);    
  SendRecipientList   (ref   nwstream,   msg.BCC);   WriteToStream    
  (ref   nwstream,   "DATA\r\n");   CheckForError   (ReadFromStream   (ref    
  nwstream),   ReplyConstants.START_INPUT);   If   (msg.ReplyTo.Name!    
  =   null   &&   msg.ReplyTo.Name.Length!   =   0)   {WriteToStream    
  (ref   nwstream,   "Reply-To:   \   ""   +   msg.ReplyTo.Name   +   "\"   <   "+    
  msg.ReplyTo.Address   +"   >\r\n");   }   else   {WriteToStream   (ref    
  nwstream,   "Reply-To:   <   "+   msg.ReplyTo.Address   +"   >\r\n");    
  }   if   (msg.From.Name!   =   null   &&   msg.From.Name.Length!    
  =   0)   {WriteToStream   (ref   nwstream,   "From:   \   ""   +    
  msg.From.Name   +   "\"   <   "+   msg.From.Address   +"   >\r\n");   }   else    
  {WriteToStream   (ref   nwstream,   "From:   <   "+   msg.From.Address   +"    
  >\r\n");   }   WriteToStream   (ref   nwstream,   "To:   "+    
  CreateAddressList   (msg.To)   +"   \r\n");   If   (msg.CC.Count!   =    
  0)   {WriteToStream   (ref   nwstream,   "CC:   "+   CreateAddressList    
  (msg.CC)   +"   \r\n");   }   WriteToStream   (ref   nwstream,   "Subject:    
  "+   msg.Subject   +"   \r\n");   If   (msg.Priority!   =   null)    
  {WriteToStream   (ref   nwstream,   "X-Priority:   "+   msg.Priority   +"    
  \r\n");   }   if   (msg.Headers.Count   >   0)   {SendHeaders   (ref   nwstream,  
  msg);   }   if   (msg.Attachments.Count   >   0   ||   msg.HtmlBody!   =    
  null)   {SendMessageBody   (ref   nwstream,   msg);   }   else    
  {WriteToStream   (ref   nwstream,   msg.Body   +   "\r\n");   }    
  WriteToStream   (ref   nwstream,   "\r\n.   \r\n");   CheckForError    
  (ReadFromStream   (ref   nwstream),   ReplyConstants.OK);    
  WriteToStream   (ref   nwstream,   "QUIT\r\n");   CheckForError    
  (ReadFromStream   (ref   nwstream),   ReplyConstants.QUIT);    
  CloseConnection   ();   }   private   bool   AuthLogin   (ref    
  NetworkStream   nwstream)   {if   (username!   =   null   &&   username.Length  
  >   0   &&   password!   =   null   &&   password.Length   >   0)   {WriteToStream    
  (ref   nwstream,   "AUTH   LOGIN\r\n");   If   (AuthImplemented    
  (ReadFromStream   (ref   nwstream)))   {WriteToStream   (ref   nwstream,    
  Convert.ToBase64String   (Encoding.ASCII.GetBytes    
  (this.username.ToCharArray   ()))   +   "\r\n");   CheckForError    
  (ReadFromStream   (ref   nwstream),   ReplyConstants.SERVER_CHALLENGE);    
  WriteToStream   (ref   nwstream,   Convert.ToBase64String    
  (Encoding.ASCII.GetBytes   (this.password.ToCharArray   ()))   +   "\r\n");    
  CheckForError   (ReadFromStream   (ref   nwstream),    
  ReplyConstants.AUTH_SUCCESSFUL);   Return   true;   }}   return    
  false;   }Top

6 楼lovvver(ElephantTalk.Bright)回复于 2006-03-09 17:04:10 得分 0

start/cmd/:  
  telnet   smtp.xx.com   25  
  ehlo/helo  
  auth   login  
  [username]  
  [password]  
  mail   from    
  rcpt   to  
  quitTop

7 楼Marg(三月的雪)回复于 2006-03-09 17:13:14 得分 0

lovvver(人生如此美好~)    
  3,Socket:并为实现ssl  
  还有GetConnection()方法在那里,  
  Top

8 楼Marg(三月的雪)回复于 2006-03-09 17:16:44 得分 0

晕,lovvver(人生如此美好~),协议我知道,我想知道怎么建立ssl的SocketTop

9 楼Marg(三月的雪)回复于 2006-03-09 19:38:24 得分 0

The   .NET   class   library   offers   SSL   support   when   you   connect   to   an   HTTP   server,   but   unfortunately   it   does   not   offer   SSL   or   TLS   support   for   other   Internet   protocols.  
  lovvver(人生如此美好~)   Read   above   sentence   .Top

相关问题

  • Could SSL be used to SMTP???
  • ssl
  • smtp quiestion
  • smtp的问题?
  • smtp的问题
  • smtp 问题
  • smtp的问题!
  • SMTP问题
  • smtp的问题?
  • smtp问题

关键词

  • mymail
  • omsg
  • myaccount
  • smtpmail
  • smtp
  • cdo
  • mail
  • test

得分解答快速导航

  • 帖主:Marg
  • jiezhi
  • lovvver

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo