public Task <SmtpCommandReply> HandleData(Stream stream)
        {
            stream.CopyTo(Body);
            Body.Seek(0, SeekOrigin.Begin);

            return(SmtpCommandReply.CreateDefault250SuccessTask());
        }
        public Task <SmtpCommandReply> HandleRset()
        {
            HeloHostname = null;
            EhloHostname = null;
            MailFrom     = null;
            Recipients   = new List <string>();

            return(SmtpCommandReply.CreateDefault250SuccessTask());
        }
        public Task <SmtpCommandReply> HandleMailFrom(string fromAddress)
        {
            var accountRepository = _container.GetInstance <IAccountRepository>();
            var account           = accountRepository.GetByNameAsync(fromAddress).Result;

            bool isLocalAccount = account != null;

            _state.FromAddress = fromAddress;
            return(SmtpCommandReply.CreateDefault250SuccessTask());
        }
        public Task <SmtpCommandReply> HandleData(Stream stream)
        {
            var blobClient    = _storageAccount.CreateCloudBlobClient();
            var mailContainer = blobClient.GetContainerReference("mail");
            var mailBlobName  = $"{Guid.NewGuid()}.eml";
            var mailBlob      = mailContainer.GetBlockBlobReference(mailBlobName);

            mailBlob.UploadFromStream(stream);

            return(SmtpCommandReply.CreateDefault250SuccessTask());
        }
        public Task <SmtpCommandReply> HandleRcptTo(string recipientAddress)
        {
            var accountRepository = _container.GetInstance <IAccountRepository>();
            var account           = accountRepository.GetByNameAsync(recipientAddress).Result;

            var recipient = new Recipient
            {
                AccountId       = account != null ? account.Id : 0,
                Address         = recipientAddress,
                OriginalAddress = recipientAddress
            };

            _state.Recipients.Add(recipient);
            return(SmtpCommandReply.CreateDefault250SuccessTask());
        }
        public Task <SmtpCommandReply> HandleRcptTo(string recipientAddress)
        {
            var blobClient          = _storageAccount.CreateCloudBlobClient();
            var recipientsContainer = blobClient.GetContainerReference("recipients");

            var recipientBlob = recipientsContainer.GetBlockBlobReference(recipientAddress);

            if (recipientBlob.Exists())
            {
                return(SmtpCommandReply.CreateDefault250SuccessTask());
            }
            else
            {
                return(Task.Run(() => new SmtpCommandReply(550, "No suchu ser.")));
            }
        }
        public void TestCompleteSmtpServerSession()
        {
            var commandHandlerMock = new Mock <ISmtpServerCommandHandler>();

            commandHandlerMock.Setup(f => f.HandleHelo("example.com")).Returns(SmtpCommandReply.CreateDefault250SuccessTask);
            commandHandlerMock.Setup(f => f.HandleMailFrom("*****@*****.**")).Returns(SmtpCommandReply.CreateDefault250SuccessTask);
            commandHandlerMock.Setup(f => f.HandleRcptTo("*****@*****.**")).Returns(SmtpCommandReply.CreateDefault250SuccessTask);

            commandHandlerMock.Setup(f => f.HandleData(It.IsAny <MemoryStreamWithFileBacking>()))
            .Callback((Stream stream) =>
                      VerifyMemoryStreamContents(stream, "Hello World\r\n"))
            .Returns(SmtpCommandReply.CreateDefault250SuccessTask());

            var data   = "Hello World\r\n.\r\n";
            var memory = new MemoryStream(Encoding.UTF8.GetBytes(data));

            var connectionMock = ConnectionMockFactory.Create(new string[]
            {
                "HELO example.com",
                "MAIL FROM: [email protected]",
                "RCPT TO: [email protected]",
                "DATA",
                "QUIT"
            }, new []
            {
                memory
            });

            SmtpServerSession session = new SmtpServerSession(commandHandlerMock.Object, new NullLog(), new SmtpServerSessionConfiguration());

            var task = session.HandleConnection(connectionMock);

            task.Wait();

            commandHandlerMock.Verify(f => f.HandleHelo("example.com"));
        }
 public Task <SmtpCommandReply> HandleMailFrom(string fromAddress)
 {
     _fromAddress = fromAddress;
     return(SmtpCommandReply.CreateDefault250SuccessTask());
 }
 public Task <SmtpCommandReply> HandleEhlo(string hostName)
 {
     return(SmtpCommandReply.CreateDefault250SuccessTask());
 }
 public Task <SmtpCommandReply> HandleRset()
 {
     return(SmtpCommandReply.CreateDefault250SuccessTask());
 }
 public Task <SmtpCommandReply> HandleRcptTo(string recipientAddress)
 {
     Recipients.Add(recipientAddress);
     return(SmtpCommandReply.CreateDefault250SuccessTask());
 }
 public Task <SmtpCommandReply> HandleHelo(string hostName)
 {
     HeloHostname = hostName;
     return(SmtpCommandReply.CreateDefault250SuccessTask());
 }