Exemplo n.º 1
0
        /// <summary>
        /// Raises <b>RcptTo</b> event.
        /// </summary>
        /// <param name="to">RCPT TO: value.</param>
        /// <param name="reply">Default SMTP server reply.</param>
        /// <returns>Returns SMTP server reply what must be sent to the connected client.</returns>
        private SMTP_Reply OnRcptTo(SMTP_RcptTo to,SMTP_Reply reply)
        {
            if(this.RcptTo != null){
                SMTP_e_RcptTo eArgs = new SMTP_e_RcptTo(this,to,reply);
                this.RcptTo(this,eArgs);

                return eArgs.Reply;
            }

            return reply;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Is called when SMTP server session gets RCPT command.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">Event data.</param>
        private void m_pSmtpServer_Session_RcptTo(object sender,SMTP_e_RcptTo e)
        {
            try{
				string mailTo = e.RcptTo.Mailbox;

				// If domain isn't specified, add default domain
				if(mailTo.IndexOf("@") == -1){
					mailTo += "@" + m_SMTP_DefaultDomain;
				}

				//1) is local domain or relay needed
				//2) can map email address to mailbox
				//3) is alias
				//4) if matches any routing pattern

				// check if e-domain is local
				if(m_pApi.DomainExists(mailTo)){
                    string user = m_pApi.MapUser(mailTo);
					if(user == null){
                        e.Reply = new SMTP_Reply(550,"No such user here.");

						// Check if mailing list.
						if(m_pApi.MailingListExists(mailTo)){
                            // Not authenticated, see is anyone access allowed
                            if(!e.Session.IsAuthenticated){
                                if(m_pApi.CanAccessMailingList(mailTo,"anyone")){
                                    e.Reply = new SMTP_Reply(250,"OK.");
                                }
                            }
                            // Authenticated, see if user has access granted
                            else{
                                if(m_pApi.CanAccessMailingList(mailTo,e.Session.AuthenticatedUserIdentity.Name)){
                                    e.Reply = new SMTP_Reply(250,"OK.");
                                }
                            }
						}
                        // At last check if matches any routing pattern.
                        else{
                            DataView dv = m_pApi.GetRoutes();
                            foreach(DataRowView drV in dv){
                                // We have matching route
                                if(Convert.ToBoolean(drV["Enabled"]) && SCore.IsAstericMatch(drV["Pattern"].ToString(),mailTo)){
                                    e.Reply = new SMTP_Reply(250,"OK.");
                                    break;
                                }
                            }
                        }
					}
					else{
                        // Validate mailbox size
                        if(m_pApi.ValidateMailboxSize(user)){
                            e.Reply = new SMTP_Reply(552,"Requested mail action aborted: Mailbox <" + e.RcptTo.Mailbox + "> is full.");                            
                        }
                        else{
                            e.Reply = new SMTP_Reply(250,"OK.");
                        }						
					}
				}
				// Foreign recipient.
				else{
                    e.Reply = new SMTP_Reply(550,"Relay not allowed.");

					// This isn't domain what we want.
					// 1)If user Authenticated, check if relay is allowed for this user.
					// 2)Check if relay is allowed for this ip.
					if(e.Session.IsAuthenticated){
						if(IsRelayAllowed(e.Session.AuthenticatedUserIdentity.Name,e.Session.RemoteEndPoint.Address)){
							e.Reply = new SMTP_Reply(250,"User not local will relay.");
						}
					}
					else if(IsRelayAllowed("",e.Session.RemoteEndPoint.Address)){
						e.Reply = new SMTP_Reply(250,"User not local will relay.");
					}		
				}
			}
			catch(Exception x){
                e.Reply = new SMTP_Reply(500,"Internal server error.");
				Error.DumpError(this.Name,x,new System.Diagnostics.StackTrace());
			}
        }