/// <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 (RcptTo != null) { SMTP_e_RcptTo eArgs = new SMTP_e_RcptTo(this, to, reply); RcptTo(this, eArgs); return eArgs.Reply; } return reply; }
private void OnSessionRcptTo(object sender, SMTP_e_RcptTo e) { _log.Debug("start processing rcpt to event"); var addressTo = e.RcptTo.Mailbox; var addressFrom = (string)e.Session.Tag; var requestInfo = _addressParsers.Select(routeParser => routeParser.ParseRequestInfo(addressTo)) .FirstOrDefault(rInfo => rInfo != null); if (requestInfo == null) { _log.WarnFormat("could not create request from the address {0}", addressTo); e.Reply = new SMTP_Reply(501, "Could not create request from the address " + addressTo); return; } CoreContext.TenantManager.SetCurrentTenant(requestInfo.Tenant); UserInfo user = CoreContext.UserManager.GetUserByEmail(addressFrom); if (user.Equals(Constants.LostUser)) { e.Reply = new SMTP_Reply(501, "Could not find user by email address " + addressFrom); return; } if (_cooldownInspector != null) { var cooldownMinutes = Math.Ceiling(_cooldownInspector.GetCooldownRemainigTime(user.ID).TotalMinutes); if (cooldownMinutes > 0) { e.Reply = new SMTP_Reply(554, string.Format("User {0} can not use the autoreply service for another {1} minutes", addressFrom, cooldownMinutes)); return; } _cooldownInspector.RegisterServiceUsage(user.ID); } requestInfo.User = user; _log.DebugFormat("created request info {0}", requestInfo); e.Session.Tags.Add(e.RcptTo.Mailbox, requestInfo); _log.Debug("complete processing rcpt to event"); }