Hola Elektro,
Mis agradecimientos por ayudarme. Veras: pude arreglar el problema del "Task". Sigo sin
poder enviar E-Mails pero logre capturar unos seguimientos.
Mi codigo, ahora, es este:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using SmtpServer;
using SmtpServer.Tracing;
namespace E_Mail_Server
{
public static class Program
{
static CancellationTokenSource _cancellationTokenSource;
static void Main(string[] args)
{
StartAsync().Wait();
}
public static async Task StartAsync()
{
_cancellationTokenSource = new CancellationTokenSource();
var options = new SmtpServerOptionsBuilder()
.ServerName("localhost")
.Port(25, 587)
.Build();
var server = new SmtpServer.SmtpServer(options);
server.SessionCreated += OnSessionCreated;
server.SessionCompleted += OnSessionCompleted;
var serverTask = server.StartAsync(_cancellationTokenSource.Token);
WaitWithoutException(serverTask);
}
static void OnSessionCreated(object sender, SessionEventArgs e)
{
Console.WriteLine("SessionCreated: {0}", e.Context.RemoteEndPoint);
e.Context.CommandExecuting += OnCommandExecuting;
}
static void OnSessionCompleted(object sender, SessionEventArgs e)
{
Console.WriteLine("SessionCompleted: {0}", e.Context.RemoteEndPoint);
e.Context.CommandExecuting -= OnCommandExecuting;
_cancellationTokenSource.Cancel();
}
static void OnCommandExecuting(object sender, SmtpCommandExecutingEventArgs e)
{
new TracingSmtpCommandVisitor(Console.Out).Visit(e.Command);
}
public static void WaitWithoutException(this Task task)
{
try
{
task.Wait();
}
catch (AggregateException e)
{
e.Handle(exception => exception is OperationCanceledException);
}
}
}
}
Y estos son los eventos de seguimientos que capture:
SessionCreated: 127.0.0.1:49510
EHLO: DomainOrAddress=X61s-PC
MAIL: Address=app@AIKI.CO.ir Parameters=
RCPT: Address=nemoschmidt7@gmail.com
DATA
Pero despues de un tiempo la consola se cierra. El reporte de salida es este:
Excepción activada: "System.OperationCanceledException" en SmtpServer.dll
Excepción activada: "System.OperationCanceledException" en mscorlib.dll
Excepción activada: "System.OperationCanceledException" en SmtpServer.dll
Excepción activada: "System.ObjectDisposedException" en System.dll
Excepción activada: "System.OperationCanceledException" en mscorlib.dll
Excepción activada: "System.OperationCanceledException" en mscorlib.dll
Excepción activada: "System.ObjectDisposedException" en System.dll
Excepción activada: "System.AggregateException" en mscorlib.dll
El programa "[8000] E-Mail Server.exe" ha finalizado con codigo 0 (0x0).
Nuevamente muchas gracias por tu ayuda.
Gracias y saludos