Skip to content

Commit

Permalink
version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
cosullivan committed May 8, 2018
1 parent d5a5b2f commit fbb5f1d
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 224 deletions.
315 changes: 95 additions & 220 deletions Src/SampleApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,277 +1,152 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Sockets;
using System.Security.Authentication;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using MailKit.Net.Smtp;
using MimeKit;
using MimeKit.Text;
using SampleApp.Examples;
using SmtpServer;
using SmtpServer.Mail;
using SampleApp.Examples;

namespace SampleApp
{
class Program
{
static void Main(string[] args)
{
var cancellationTokenSource = new CancellationTokenSource();

if (args == null || args.Length == 0)
{
var serverTask = RunServerAsync(cancellationTokenSource.Token);
var clientTask1 = RunClientAsync("A", forceConnection: false, cancellationToken: cancellationTokenSource.Token);
var clientTask2 = RunClientAsync("B", forceConnection: false, cancellationToken: cancellationTokenSource.Token);
var clientTask3 = RunClientAsync("C", forceConnection: false, cancellationToken: cancellationTokenSource.Token);
SecureServerExample.Run();
}

Console.WriteLine("Press any key to continue");
Console.ReadKey();
//static void Main(string[] args)
//{
// var cancellationTokenSource = new CancellationTokenSource();

// if (args == null || args.Length == 0)
// {
// var serverTask = RunServerAsync(cancellationTokenSource.Token);
// var clientTask1 = RunClientAsync("A", forceConnection: false, cancellationToken: cancellationTokenSource.Token);
// var clientTask2 = RunClientAsync("B", forceConnection: false, cancellationToken: cancellationTokenSource.Token);
// var clientTask3 = RunClientAsync("C", forceConnection: false, cancellationToken: cancellationTokenSource.Token);

cancellationTokenSource.Cancel();
// Console.WriteLine("Press any key to continue");
// Console.ReadKey();

serverTask.WaitWithoutException();
clientTask1.WaitWithoutException();
clientTask2.WaitWithoutException();
clientTask3.WaitWithoutException();
// cancellationTokenSource.Cancel();

return;
}
// serverTask.WaitWithoutException();
// clientTask1.WaitWithoutException();
// clientTask2.WaitWithoutException();
// clientTask3.WaitWithoutException();

if (args[0] == "server")
{
var serverTask = RunServerAsync(cancellationTokenSource.Token);
// return;
// }

Console.WriteLine("Press any key to continue");
Console.ReadKey();
// if (args[0] == "server")
// {
// var serverTask = RunServerAsync(cancellationTokenSource.Token);

cancellationTokenSource.Cancel();
// Console.WriteLine("Press any key to continue");
// Console.ReadKey();

serverTask.WaitWithoutException();
// cancellationTokenSource.Cancel();

return;
}
// serverTask.WaitWithoutException();

if (args[0] == "client")
{
var clientTask = RunClientAsync(args[1], cancellationToken: cancellationTokenSource.Token);
// return;
// }

Console.WriteLine("Press any key to continue");
Console.ReadKey();
// if (args[0] == "client")
// {
// var clientTask = RunClientAsync(args[1], cancellationToken: cancellationTokenSource.Token);

cancellationTokenSource.Cancel();
// Console.WriteLine("Press any key to continue");
// Console.ReadKey();

clientTask.WaitWithoutException();
}
// cancellationTokenSource.Cancel();

if (args[0] == "folder")
{
var clientTask = RunClientAsync(args[1], cancellationToken: cancellationTokenSource.Token);
// clientTask.WaitWithoutException();
// }

Console.WriteLine("Press any key to continue");
Console.ReadKey();
// if (args[0] == "folder")
// {
// var clientTask = RunClientAsync(args[1], cancellationToken: cancellationTokenSource.Token);

cancellationTokenSource.Cancel();
// Console.WriteLine("Press any key to continue");
// Console.ReadKey();

clientTask.WaitWithoutException();
}
}
// cancellationTokenSource.Cancel();

static async Task RunServerAsync(CancellationToken cancellationToken)
{
var options = new SmtpServerOptionsBuilder().Port(9025).Build();
// clientTask.WaitWithoutException();
// }
//}

var smtpServer = new SmtpServer.SmtpServer(options);
//static async Task RunServerAsync(CancellationToken cancellationToken)
//{
// var options = new SmtpServerOptionsBuilder().Port(9025).Build();

await smtpServer.StartAsync(cancellationToken);
}
// var smtpServer = new SmtpServer.SmtpServer(options);

static async Task RunClientAsync(
string name,
int limit = Int32.MaxValue,
bool forceConnection = true,
CancellationToken cancellationToken = default(CancellationToken))
{
//var message = MimeKit.MimeMessage.Load(ParserOptions.Default, @"C:\Dev\Enron Corpus\maildir\allen-p\inbox\31_");

var message = new MimeMessage();

message.From.Add(new MailboxAddress("from@sample.com"));
message.To.Add(new MailboxAddress("to@sample.com"));
message.Subject = "Hello";
message.Body = new TextPart("plain")
{
Text = "Hello World"
};

var stopwatch = new Stopwatch();
stopwatch.Start();

var counter = 1;
using (var smtpClient = new SmtpClient())
{
while (limit-- > 0 && cancellationToken.IsCancellationRequested == false)
{
//Console.WriteLine("Name={0} Count={1}", name, counter);

try
{
if (smtpClient.IsConnected == false)
{
await smtpClient.ConnectAsync("localhost", 9025, false, cancellationToken);

if (smtpClient.Capabilities.HasFlag(SmtpCapabilities.Authentication))
{
await smtpClient.AuthenticateAsync("user", "password", cancellationToken);
}
}

await smtpClient.SendAsync(message, cancellationToken).ConfigureAwait(false);
}
catch (Exception exception)
{
if (cancellationToken.IsCancellationRequested)
{
break;
}
}

if (forceConnection)
{
await smtpClient.DisconnectAsync(true, cancellationToken);
}

counter++;
}
}

stopwatch.Stop();

Console.WriteLine();
Console.WriteLine("{0} Finished.", name);
Console.WriteLine(" {0} Messages Sent.", counter);
Console.WriteLine(" {0} Time Taken (ms).", stopwatch.ElapsedMilliseconds);
Console.WriteLine(" {0} Throughput (mps).", counter / (stopwatch.ElapsedMilliseconds / 1000.0));
}
// await smtpServer.StartAsync(cancellationToken);
//}

//static async Task SendMessageAsync(SmtpClient smtpClient, string name, int counter, CancellationToken cancellationToken = default(CancellationToken))
//static async Task RunClientAsync(
// string name,
// int limit = Int32.MaxValue,
// bool forceConnection = true,
// CancellationToken cancellationToken = default(CancellationToken))
//{
// var message = new MimeKit.MimeMessage();
// message.From.Add(new MimeKit.MailboxAddress($"{name}{counter}@test.com"));
// message.To.Add(new MimeKit.MailboxAddress("sample@test.com"));
// message.Subject = $"{name} {counter}";
// //var message = MimeKit.MimeMessage.Load(ParserOptions.Default, @"C:\Dev\Enron Corpus\maildir\allen-p\inbox\31_");

// var message = new MimeMessage();

// message.Body = new TextPart(TextFormat.Plain)
// message.From.Add(new MailboxAddress("from@sample.com"));
// message.To.Add(new MailboxAddress("to@sample.com"));
// message.Subject = "Hello";
// message.Body = new TextPart("plain")
// {
// Text = ".Assunto teste acento çãõáéíóú"
// Text = "Hello World"
// };

// await smtpClient.SendAsync(message, cancellationToken).ConfigureAwait(false);
//}
// var stopwatch = new Stopwatch();
// stopwatch.Start();

//static async Task RunFolderAsync(string folder, string pattern = "*", CancellationToken cancellationToken = default(CancellationToken))
//{
// foreach (var directory in Directory.GetDirectories(folder, "*", SearchOption.AllDirectories))
// var counter = 1;
// using (var smtpClient = new SmtpClient())
// {
// Console.WriteLine(directory);
// cancellationToken.ThrowIfCancellationRequested();

// foreach (var file in Directory.GetFiles(directory, pattern).ToList())
// while (limit-- > 0 && cancellationToken.IsCancellationRequested == false)
// {
// cancellationToken.ThrowIfCancellationRequested();
// Console.WriteLine(new FileInfo(file).Name);
// //Console.WriteLine("Name={0} Count={1}", name, counter);

// MimeKit.MimeMessage message;
// try
// {
// message = MimeKit.MimeMessage.Load(ParserOptions.Default, file);
// }
// catch
// {
// continue;
// }

// using (var smtpClient = new SmtpClient())
// {
// try
// if (smtpClient.IsConnected == false)
// {
// await smtpClient.ConnectAsync("localhost", 9025, false, cancellationToken);
// await smtpClient.AuthenticateAsync("user", "password", cancellationToken);

// await smtpClient.SendAsync(message, cancellationToken).ConfigureAwait(false);
// if (smtpClient.Capabilities.HasFlag(SmtpCapabilities.Authentication))
// {
// await smtpClient.AuthenticateAsync("user", "password", cancellationToken);
// }
// }
// catch (Exception exception)

// await smtpClient.SendAsync(message, cancellationToken).ConfigureAwait(false);
// }
// catch (Exception exception)
// {
// if (cancellationToken.IsCancellationRequested)
// {
// Console.WriteLine(exception);
// break;
// }
// }

// if (forceConnection)
// {
// await smtpClient.DisconnectAsync(true, cancellationToken);
// }
// }
// }
//}

//static async Task RunFileAsync(string file, CancellationToken cancellationToken = default(CancellationToken))
//{
// var message = MimeKit.MimeMessage.Load(ParserOptions.Default, file);

// using (var smtpClient = new SmtpClient())
// {
// try
// {
// await smtpClient.ConnectAsync("localhost", 9025, false, cancellationToken);
// await smtpClient.AuthenticateAsync("user", "password", cancellationToken);

// await smtpClient.SendAsync(message, cancellationToken).ConfigureAwait(false);
// }
// catch (Exception exception)
// {
// Console.WriteLine(exception);
// counter++;
// }

// await smtpClient.DisconnectAsync(true, cancellationToken);
// }
//}


//static void OnSmtpServerSessionCreated(object sender, SessionEventArgs e)
//{
// Console.WriteLine("SessionCreated: {0}", e.Context.RemoteEndPoint);

// e.Context.CommandExecuting += OnCommandExecuting;
//}

//static void OnCommandExecuting(object sender, SmtpCommandExecutingEventArgs e)
//{
// new TracingSmtpCommandVisitor(Console.Out).Visit(e.Command);
//}

//static void OnSmtpServerSessionCompleted(object sender, SessionEventArgs e)
//{
// e.Context.CommandExecuting -= OnCommandExecuting;

// Console.WriteLine("SessionCompleted: {0}", e.Context.RemoteEndPoint);
//}

//static bool IgnoreCertificateValidationFailureForTestingOnly(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
//{
// return true;
//}

//static X509Certificate2 CreateCertificate()
//{
// // to create an X509Certificate for testing you need to run MAKECERT.EXE and then PVK2PFX.EXE
// // http://www.digitallycreated.net/Blog/38/using-makecert-to-create-certificates-for-development

// var certificate = File.ReadAllBytes(@"C:\Dropbox\Documents\Cain\Programming\SmtpServer\SmtpServer.pfx");
// var password = File.ReadAllText(@"C:\Dropbox\Documents\Cain\Programming\SmtpServer\SmtpServerPassword.txt");
// stopwatch.Stop();

// return new X509Certificate2(certificate, password);
// Console.WriteLine();
// Console.WriteLine("{0} Finished.", name);
// Console.WriteLine(" {0} Messages Sent.", counter);
// Console.WriteLine(" {0} Time Taken (ms).", stopwatch.ElapsedMilliseconds);
// Console.WriteLine(" {0} Throughput (mps).", counter / (stopwatch.ElapsedMilliseconds / 1000.0));
//}
}
}
8 changes: 4 additions & 4 deletions Src/SmtpServer/SmtpServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net45;netstandard1.3</TargetFrameworks>
<AssemblyName>SmtpServer</AssemblyName>
<RootNamespace>SmtpServer</RootNamespace>
<Version>5.0.0</Version>
<Version>5.1.0</Version>
<Description>.NET SmtpServer</Description>
<Authors>Cain O'Sullivan</Authors>
<Company />
Expand All @@ -14,9 +14,9 @@
<PackageTags>smtp smtpserver smtp server</PackageTags>
<PackageLicenseUrl>https://raw.githubusercontent.com/cosullivan/SmtpServer/master/LICENSE</PackageLicenseUrl>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<FileVersion>5.0.0.0</FileVersion>
<PackageReleaseNotes>Added secure by default option for ports.
<AssemblyVersion>5.1.0.0</AssemblyVersion>
<FileVersion>5.1.0.0</FileVersion>
<PackageReleaseNotes>Fixed issue that was causing an increase in memory under high throughput.
</PackageReleaseNotes>
</PropertyGroup>

Expand Down

0 comments on commit fbb5f1d

Please sign in to comment.