关于ssl,smtp

Marg 2006-03-09 04:35:03
我想用smtp协议发mail,可不知道怎么用c#建立一个ssl的Socket。
...全文
233 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Marg 2006-03-09
  • 打赏
  • 举报
回复
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 .
Marg 2006-03-09
  • 打赏
  • 举报
回复
晕,lovvver(人生如此美好~),协议我知道,我想知道怎么建立ssl的Socket
Marg 2006-03-09
  • 打赏
  • 举报
回复
lovvver(人生如此美好~)
3,Socket:并为实现ssl
还有GetConnection()方法在那里,
lovvver 2006-03-09
  • 打赏
  • 举报
回复
start/cmd/:
telnet smtp.xx.com 25
ehlo/helo
auth login
[username]
[password]
mail from
rcpt to
quit
lovvver 2006-03-09
  • 打赏
  • 举报
回复
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; }
missQJM 2006-03-09
  • 打赏
  • 举报
回复
够狠
只能上CSDN
lovvver 2006-03-09
  • 打赏
  • 举报
回复
参考一下:
http://systemwebmail.com/
Marg 2006-03-09
  • 打赏
  • 举报
回复
公司除了csdn什么都上不去,麻烦贴下,谢谢
jiezhi 2006-03-09
  • 打赏
  • 举报
回复
参考:
http://www.mentalis.org/soft/projects/ssocket/

110,555

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧