/// <summary> /// Raises <b>MailFrom</b> event. /// </summary> /// <param name="from">MAIL FROM: 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 OnMailFrom(SMTP_MailFrom from,SMTP_Reply reply) { if(this.MailFrom != null){ SMTP_e_MailFrom eArgs = new SMTP_e_MailFrom(this,from,reply); this.MailFrom(this,eArgs); return eArgs.Reply; } return reply; }
/// <summary> /// Is called when SMTP server session gets MAIL command. /// </summary> /// <param name="sender">Sender.</param> /// <param name="e">Event data.</param> private void m_pSmtpServer_Session_MailFrom(object sender,SMTP_e_MailFrom e) { if(m_SMTP_RequireAuth && !e.Session.IsAuthenticated){ e.Reply = new SMTP_Reply(530,"5.7.0 Authentication required."); return; } // Block blank domain(user@) email addresses. if(e.MailFrom.Mailbox.IndexOf('@') != -1 && e.MailFrom.Mailbox.Substring(e.MailFrom.Mailbox.IndexOf('@') + 1).Length < 1){ e.Reply = new SMTP_Reply(501,"MAIL FROM: address(" + e.MailFrom + ") domain name must be specified."); return; } try{ //--- Filter sender -----------------------------------------------------// DataView dvFilters = m_pApi.GetFilters(); dvFilters.RowFilter = "Enabled=true AND Type='ISmtpSenderFilter'"; dvFilters.Sort = "Cost"; foreach(DataRowView drViewFilter in dvFilters){ string assemblyFile = drViewFilter.Row["Assembly"].ToString(); // File is without path probably, try to load it from filters folder if(!File.Exists(assemblyFile)){ assemblyFile = m_pOwnerServer.StartupPath + "\\Filters\\" + assemblyFile; } Assembly ass = Assembly.LoadFrom(assemblyFile); Type tp = ass.GetType(drViewFilter.Row["ClassName"].ToString()); object filterInstance = Activator.CreateInstance(tp); ISmtpSenderFilter filter = (ISmtpSenderFilter)filterInstance; string error = null; if(!filter.Filter(e.MailFrom.Mailbox,m_pApi,e.Session,out error)){ if(error != null){ e.Reply = new SMTP_Reply(550,error); } else{ e.Reply = new SMTP_Reply(550,"Sender rejected."); } return; } } //----------------------------------------------------------------------// } catch(Exception x){ e.Reply = new SMTP_Reply(500,"Internal server error."); Error.DumpError(this.Name,x,new System.Diagnostics.StackTrace()); } }