社区
C#
帖子详情
关于ssl,smtp
Marg
2006-03-09 04:35:03
我想用smtp协议发mail,可不知道怎么用c#建立一个ssl的Socket。
...全文
280
9
打赏
收藏
关于ssl,smtp
我想用smtp协议发mail,可不知道怎么用c#建立一个ssl的Socket。
复制链接
扫一扫
分享
举报
写回复
配置赞助广告
用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/
Python 函数之参数、局部变量
5、参数Python中的参数分如下几类: 必备参数 命名参数 缺省参数 不定长参数 5.1必备参数必备参数在传入时,函数调时给的参数数量、顺序都必须和声明时一样,否则就会报错。如: 声明一个这样的函数:def info(name, age, tel) :调用info函数时,必须传入三个参数,并且参数的顺序也必须是name, age, tel,如:info('jack', 20,'135678678
chatgpt赋能python:Python函数局部变量:什么是局部变量?
在Python中,函数局部变量是在函数内部定义的变量。它们的作用域仅限于函数的内部。一旦函数执行完成,它们就会被删除。定义一个局部变量非常简单,只需要在函数内部使用赋值语句即可。例如,上面的代码定义了一个名为x的局部变量。这个变量只能在函数内部使用。如果我们想在函数外部使用这个变量,就必须将它定义为全局变量。本文由chatgpt生成,文章没有在chatgpt生成的基础上进行任何的修改。以上只是chatgpt能力的冰山一角。作为通用的Aigc大模型,只是展现它原本的实力。对于颠覆工作方式的ChatGPT。
chatgpt赋能python:Python函数中关于局部变量的介绍
Python 函数中的局部变量指的是在函数内部声明的变量,这些变量只能在函数内部使用,不能在函数外部使用。在函数内部声明的变量,其作用域仅限于函数内部,因此,称这些变量为“局部变量”。x = 5print(x)func()这段代码定义了一个函数func(),其中声明了一个名为x的局部变量,它的值为5,然后在函数内使用print()函数打印x的值。因为x是一个局部变量,所以它只能在函数内部使用,如果在函数外部使用x,会出现 NameError 的错误。本文由chatgpt生成,文章没有在chatgpt。
python局部变量函数_22、Python 函数的局部变量
局部变量:在函数里面赋值的变量为局部变量、只在本函数内生效在一个函数里面,局部变量具有最高优先级,函数可以调用全局变量、函数外的代码不可以调用函数里的变量name = "LinYaoHong"def change_name():name = "蔺要红" #局部变量print("在函数里改名",name,id(name)) #id(name)内存地址不同change_name()print(na...
python局部变量函数_python函数局部变量用法实例分析
本文实例讲述了python函数局部变量用法。分享给大家供大家参考。具体分析如下:当你在函数定义内声明变量的时候,它们与函数外具有相同名称的其他变量没有任何关系,即变量名称对于函数来说是 局部 的。这称为变量的 作用域 。所有变量的作用域是它们被定义的块,从它们的名称被定义的那点开始。一、使用局部变量示例如下:#!/usr/bin/python# Filename: func_local.pydef...
C#
111,128
社区成员
642,536
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章