Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
The implementation of the in-memory POP3 server.
using System;
using System.IO;
using System.Net;
using System.Text;
using LumiSoft.Net;
using LumiSoft.Net.POP3.Server;
namespace MockEmail
{
public class Pop3Server : IDisposable
{
private readonly POP3_Server server = new POP3_Server();
public Pop3Server(string message)
{
server.Bindings = new[] {new IPBindInfo("localhost", BindInfoProtocol.TCP, IPAddress.Loopback, 110)};
server.SessionCreated += (sender, args) =>
{
var session = args.Session;
session.Authenticate += (o, authenticate) => authenticate.IsAuthenticated = true;
session.GetMessagesInfo +=
(o, info) =>
info.Messages.Add(new POP3_ServerMessage(Guid.NewGuid().ToString(), message.Length));
session.GetMessageStream +=
(o, stream) => stream.MessageStream = new MemoryStream(Encoding.UTF8.GetBytes(message));
};
}
public void Start()
{
server.Start();
}
public void Dispose()
{
server.Stop();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment