Created
April 23, 2013 10:19
-
-
Save alexfalkowski/5442421 to your computer and use it in GitHub Desktop.
The implementation of the in-memory POP3 server.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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