/// <summary> /// Handle the RCPT TO:<address> command. /// </summary> private void Rcpt( SMTPContext context, string argument ) { if( context.LastCommand == COMMAND_MAIL || context.LastCommand == COMMAND_RCPT ) { string address = ParseAddress( argument ); if( address != null ) { try { EmailAddress emailAddress = new EmailAddress( address ); // Check to make sure we want to accept this message. //if( recipientFilter.AcceptRecipient( context, emailAddress ) ) //{ context.Message.AddToAddress( emailAddress ); context.LastCommand = COMMAND_RCPT; context.WriteLine( MESSAGE_OK ); //if( log.IsDebugEnabled ) log.Debug( String.Format( "Connection {0}: RcptTo address: {1} accepted.", context.ConnectionId, address ) ); //} //else //{ // context.WriteLine(MESSAGE_UNKNOWN_USER); //if (log.IsDebugEnabled) log.Debug(String.Format("Connection {0}: RcptTo address: {1} rejected. Did not pass Address Filter.", context.ConnectionId, address)); //} } catch( InvalidEmailAddressException ) { //if( log.IsDebugEnabled ) log.Debug( String.Format( "Connection {0}: RcptTo argument: {1} rejected. Should be from:<*****@*****.**>", context.ConnectionId, argument ) ); context.WriteLine( MESSAGE_INVALID_ADDRESS ); } } else { //if( log.IsDebugEnabled ) log.Debug( String.Format( "Connection {0}: RcptTo argument: {1} rejected. Should be from:<*****@*****.**>", context.ConnectionId, argument ) ); context.WriteLine( MESSAGE_INVALID_ADDRESS ); } } else { context.WriteLine( MESSAGE_INVALID_COMMAND_ORDER ); } }
/// <summary> /// Accepts only local email. /// </summary> /// <param name='context'>The SMTPContext</param> /// <param name='recipient'>TODO - add parameter description</param> public virtual bool AcceptRecipient( SMTPContext context, EmailAddress recipient ) { return domain.Equals( recipient.Domain ); }
/// <summary> /// Handle the MAIL FROM:<address> command. /// </summary> private void Mail( SMTPContext context, string argument ) { bool addressValid = false; if( context.LastCommand == COMMAND_HELO ) { string address = ParseAddress( argument ); if( address != null ) { try { EmailAddress emailAddress = new EmailAddress( address ); context.Message.FromAddress = emailAddress; context.LastCommand = COMMAND_MAIL; addressValid = true; context.WriteLine( MESSAGE_OK ); //if( log.IsDebugEnabled ) log.Debug( String.Format( "Connection {0}: MailFrom address: {1} accepted.", context.ConnectionId, address ) ); } catch( InvalidEmailAddressException ) { // This is fine, just fall through. } } // If the address is invalid, inform the client. if( !addressValid ) { //if( log.IsDebugEnabled ) log.Debug( String.Format( "Connection {0}: MailFrom argument: {1} rejected. Should be from:<*****@*****.**>", context.ConnectionId, argument ) ); context.WriteLine( MESSAGE_INVALID_ADDRESS ); } } else { context.WriteLine( MESSAGE_INVALID_COMMAND_ORDER ); } }
/// <summary>Addes an address to the recipient list.</summary> public void AddToAddress( EmailAddress address ) { recipientAddresses.Add( address ); }