/// <summary> /// Gets email hosts. /// </summary> /// <param name="domain">Email domain. For example: 'domain.com'.</param> /// <returns>Returns email hosts in priority order.</returns> /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and and this method is accessed.</exception> /// <exception cref="ArgumentNullException">Is raised when <b>domain</b> is null reference.</exception> /// <exception cref="ArgumentException">Is raised when any of the arguments has invalid value.</exception> /// <exception cref="DNS_ClientException">Is raised when DNS server returns error.</exception> /// <exception cref="IOException">Is raised when IO reletaed error happens.</exception> public HostEntry[] GetEmailHosts(string domain) { if(m_IsDisposed){ throw new ObjectDisposedException(this.GetType().Name); } if(domain == null){ throw new ArgumentNullException("domain"); } if(domain == string.Empty){ throw new ArgumentException("Argument 'domain' value must be specified.","domain"); } ManualResetEvent wait = new ManualResetEvent(false); using(Dns_Client.GetEmailHostsAsyncOP op = new Dns_Client.GetEmailHostsAsyncOP(domain)){ op.CompletedAsync += delegate(object s1,EventArgs<Dns_Client.GetEmailHostsAsyncOP> e1){ wait.Set(); }; if(!this.GetEmailHostsAsync(op)){ wait.Set(); } wait.WaitOne(); wait.Close(); if(op.Error != null){ throw op.Error; } else{ return op.Hosts; } } }
/// <summary> /// Start processing relay message. /// </summary> /// <param name="state">User data.</param> internal void Start(object state) { try{ if(m_pServer.Logger != null){ m_pSmtpClient.Logger = new Logger(); m_pSmtpClient.Logger.WriteLog += new EventHandler<WriteLogEventArgs>(SmtpClient_WriteLog); } LogText("Starting to relay message '" + m_pRelayItem.MessageID + "' from '" + m_pRelayItem.From + "' to '" + m_pRelayItem.To + "'."); // Resolve email target hosts. if(m_RelayMode == Relay_Mode.Dns){ Dns_Client.GetEmailHostsAsyncOP op = new Dns_Client.GetEmailHostsAsyncOP(m_pRelayItem.To); op.CompletedAsync += delegate(object s1,EventArgs<Dns_Client.GetEmailHostsAsyncOP> e1){ EmailHostsResolveCompleted(m_pRelayItem.To,op); }; if(!m_pServer.DnsClient.GetEmailHostsAsync(op)){ EmailHostsResolveCompleted(m_pRelayItem.To,op); } } // Resolve smart hosts IP addresses. else if(m_RelayMode == Relay_Mode.SmartHost){ string[] smartHosts = new string[m_pSmartHosts.Length]; for(int i=0;i<m_pSmartHosts.Length;i++){ smartHosts[i] = m_pSmartHosts[i].Host; } Dns_Client.GetHostsAddressesAsyncOP op = new Dns_Client.GetHostsAddressesAsyncOP(smartHosts); op.CompletedAsync += delegate(object s1,EventArgs<Dns_Client.GetHostsAddressesAsyncOP> e1){ SmartHostsResolveCompleted(op); }; if(!m_pServer.DnsClient.GetHostsAddressesAsync(op)){ SmartHostsResolveCompleted(op); } } } catch(Exception x){ Dispose(x); } }