Comments (20)
Please try to use the AppServer's method "void ResetSessionSecurity(IAppSession session, SslProtocols security)".
from supersocket.
Sorry for the late answer. I was on a conference the last days.
I try with the ResetSessionSecurity method, but the mail library throws a exception.
Socket connection has been refused by remote host. InnerException message follows: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. InnerException message follows: An existing connection was forcibly closed by the remote host ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at a.ae.Read(Byte[] buffer, Int32 offset, Int32 count)
at System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
from supersocket.
Where did this exception come from? Was it from SuperSocket?
from supersocket.
No the exception throws the mailbee library, is my test framework. (https://www.nuget.org/packages/MailBee.NET)
Here a simple Example of the Mailserver
class Program
{
static void Main(string[] args)
{
var example = new Example();
example.Start();
Console.WriteLine("Mailserver started");
Console.ReadLine();
}
}
public class Example
{
private MailServer _mailServer;
public void Start()
{
//Only need visual studio copy the SocketEngine.dll
var configuration = new SuperSocket.SocketEngine.Configuration.Server();
//Configuration
var config = new SuperSocket.SocketBase.Config.ServerConfig();
config.Port = 25;
config.MaxConnectionNumber = 10;
config.ClearIdleSession = true;
config.ClearIdleSessionInterval = 60; //seconds
config.IdleSessionTimeOut = 60;
config.MaxRequestLength = 2097152; //2MB
config.ListenBacklog = 5; //Waiting Connection Pool
config.SendBufferSize = 1024;
config.ReceiveBufferSize = 1024;
config.SyncSend = true;
config.LogBasicSessionActivity = false;
config.Certificate = new SuperSocket.SocketBase.Config.CertificateConfig() { FilePath = "test.pfx", Password = "test" };
this._mailServer = new MailServer();
this._mailServer.NewRequestReceived += new RequestHandler<SmtpSession, StringRequestInfo>(NewRequestReceived);
this._mailServer.Setup(config);
this._mailServer.Start();
}
private void NewRequestReceived(SmtpSession session, StringRequestInfo requestInfo)
{
session.ProccessRequest(requestInfo.Key, requestInfo.Body);
}
public class MailServer : AppServer<SmtpSession>
{
public MailServer() : base(new CommandLineReceiveFilterFactory(Encoding.UTF8, new MailCommandParser()))
{
}
}
public class SmtpSession : AppSession<SmtpSession>
{
private bool _readyForData;
protected override void OnSessionStarted()
{
Thread.Sleep(20);
this.Send("220 Mail Service ready");
}
public void ProccessRequest(string key, string data)
{
if (this._readyForData)
{
if (!String.IsNullOrEmpty(key))
{
this.DataRequest(key);
return;
}
this.DataRequest(data);
}
else
{
this.CommandRequest(key, data);
}
}
private void CommandRequest(string key, string data)
{
switch (key.ToUpper())
{
case "EHLO":
this.Send("250-Hello");
this.Send("250-STARTTLS");
this.Send("250 OK");
return;
case "HELO":
this.Send("250 Hello");
return;
case "RSET":
this.Send("250 Ok");
return;
case "NOOP":
this.Send("250 Ok");
return;
case "STARTTLS":
//Switch in TLS Session
this.Send("220 Ready to start TLS");
this.AppServer.ResetSessionSecurity(this, System.Security.Authentication.SslProtocols.Default);
return;
case "MAIL FROM":
this.Send("250 Sender ok");
return;
case "RCPT TO":
this.Send("250 Recipient ok");
return;
case "DATA":
this._readyForData = true;
this.Send("354 Go ahead, make my day");
return;
case "QUIT":
this.Send("221 Closing");
Thread.Sleep(20);
this.Close();
return;
}
this.Send("500 Unrecognized command");
}
private void DataRequest(string data)
{
#region Receive Data End Char
if (data.Equals(".", StringComparison.Ordinal))
{
this.Send("250 Queued");
this._readyForData = false;
}
#endregion
}
}
public class MailCommandParser : IRequestInfoParser<StringRequestInfo>
{
public StringRequestInfo ParseRequestInfo(string source)
{
if (source.StartsWith("EHLO", StringComparison.OrdinalIgnoreCase))
{
return ParseRequestInfo(source, " ");
}
if (source.StartsWith("HELO", StringComparison.OrdinalIgnoreCase))
{
return ParseRequestInfo(source, " ");
}
if (source.StartsWith("MAIL FROM", StringComparison.OrdinalIgnoreCase))
{
return ParseRequestInfo(source, ":");
}
if (source.StartsWith("RCPT TO", StringComparison.OrdinalIgnoreCase))
{
return ParseRequestInfo(source, ":");
}
if (source.StartsWith("DATA", StringComparison.OrdinalIgnoreCase))
{
return new StringRequestInfo(source, String.Empty, null);
}
if (source.StartsWith("RSET", StringComparison.OrdinalIgnoreCase))
{
return new StringRequestInfo(source, String.Empty, null);
}
if (source.StartsWith("NOOP", StringComparison.OrdinalIgnoreCase))
{
return new StringRequestInfo(source, String.Empty, null);
}
if (source.StartsWith("STARTTLS", StringComparison.OrdinalIgnoreCase))
{
return new StringRequestInfo(source, String.Empty, null);
}
if (source.StartsWith("QUIT", StringComparison.OrdinalIgnoreCase))
{
return new StringRequestInfo(source, "", null);
}
return new StringRequestInfo(String.Empty, source, null);
}
private StringRequestInfo ParseRequestInfo(string source, string spliter)
{
var pos = source.IndexOf(spliter);
var name = String.Empty;
var param = String.Empty;
if (pos > 0)
{
name = source.Substring(0, pos);
param = source.Substring(pos + 1);
}
else
{
name = source;
}
return new StringRequestInfo(name, param.Trim(), null);
}
}
}
from supersocket.
Can I have a full stack trace of that exception?
I cannot find where that exception from by the text you posted.
from supersocket.
This is a example client, you can change the "EnableSsl" to false it works, but with true not work
static void Main(string[] args)
{
CreateTestMessage("localhost");
Console.ReadLine();
}
public static void CreateTestMessage(string server)
{
try
{
var from = "[email protected]";
var to = "[email protected]";
var message = new MailMessage(from, to);
message.Subject = "Using the new SMTP client.";
message.Body = @"Using this new feature, you can send an e-mail message from an application very easily.";
var client = new SmtpClient(server);
client.EnableSsl = true;
client.Send(message);
Console.WriteLine("Send mail successful");
}
catch (Exception exception)
{
Console.WriteLine(exception.Message);
}
}
from supersocket.
I hope with this 2 examples you can follow my problem?
from supersocket.
Do you mean the exception you mentioned was thrown from the client side?
from supersocket.
Yes the client throw this exception. But the demo client i post here use the .net framework classes. In my private client i use the mailbee library but this one need a licence...
from supersocket.
Could you check the logs of the server side to see what happened?
from supersocket.
i have add log4net in my demo server project. but only one line is in the log
2016-06-23 18:02:32,351 [9] INFO MailServer-62476613 - The server instance MailServer-62476613 has been started!
from supersocket.
Reproduce this issue and then check the error log file.
from supersocket.
err.log is emtpy, if it possible ResetSessionSecurity close the current connection and open a new one, instead update the current connection to TLS
from supersocket.
Could you debug the method ResetSessionSecurity to see what happen?
Probably the client try to connect the secure port 465 of the smtp server.
https://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol
from supersocket.
I have check this possibility with the port 465, with my reference project (https://github.com/cosullivan/SmtpServer) here also only port 25 is open and it works well.
SampleApp (SmtpServer Project)
var cancellationTokenSource = new CancellationTokenSource();
var options = new OptionsBuilder()
.ServerName("SmtpServer SampleApp")
.Port(25)
.MessageStore(new ConsoleMessageStore())
.MailboxFilter(new ConsoleMailboxFilter())
.Certificate(new System.Security.Cryptography.X509Certificates.X509Certificate("test.pfx", "test"))
.Build();
var serverTask = RunServerAsync(options, cancellationTokenSource.Token);
from supersocket.
i found a exception but if not available in the log file...
AsyncStreamSocketSession -> OnSessionStarting
System.NullReferenceException: Object reference not set to an instance to an object
from supersocket.
Could you debug the method ResetSessionSecurity to see what happen?
from supersocket.
on this position i have the exception
AsyncStreamSocketSession
OnSessionStarting
m_Stream.BeginRead(m_ReadBuffer, m_Offset, m_Length, OnStreamEndRead, m_Stream);
m_Stream is null
i have also check why is not in the error log, IsIgnorableException is true
//This exception is ignored, needn't log it
if (IsIgnorableException(exception, out socketErrorCode))
return;
from supersocket.
Can you reproduce the exception?
from supersocket.
Yes, I found it.
But it is very difficult to fix in this version.
from supersocket.
Related Issues (20)
- 在supersocket2.0中,如何在PipeChannel.ReadPipeAsync中,两个相邻的包超过单位时间,则舍弃掉旧包? HOT 2
- websocket在大量连接下发送数据遇到一个BUG
- How do I get unfiltered raw packets?
- Set Licence type & repo url on package info
- 发布的MyGet Version 下载问题 HOT 2
- Breaking changes were introduced in 2.0 beta.19.429 HOT 2
- 用AsyncTcpSession 来创建客户端连接,有时候会连不上,多久都没有返回结束? HOT 2
- 客户端同时大量发送和接收数据时报错: Writing is not allowed after writer was completed. HOT 8
- 在Unity中启动服务器无效,Unity卡住 HOT 6
- SuperSocket可以在哪些平台中运行
- 请问如何实现一个客户端连接生成一个独立的日志文件? HOT 1
- 请问如何实现一个客户端连接生成一个独立的日志文件? HOT 2
- Several errors in the unit tests in the build pipeline
- 服务器接收到数据全是0 HOT 3
- NativeAot HOT 3
- UsePackageHandler里收不到数据呢 HOT 1
- 下面的EasyClient发送数据服务端接收不到呢 HOT 4
- 为什么2.0中没有【可允许连接的最大连接数】的配置? HOT 1
- 无法在ICommand使用依赖注入服务
- SuperSocket not working in Xamarin.Forms HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from supersocket.