/// <summary> /// Starts connection to the specified host. /// </summary> /// <param name="host">Host name or IP address.</param> /// <param name="port">Port to connect.</param> /// <param name="ssl">Specifies if connects to SSL end point.</param> /// <param name="callback">Callback to call when the connect operation is complete.</param> /// <param name="state">User data.</param> /// <returns>An IAsyncResult that references the asynchronous connection.</returns> /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception> /// <exception cref="InvalidOperationException">Is raised when TCP client is already connected.</exception> /// <exception cref="ArgumentException">Is raised when any of the arguments has invalid value.</exception> public IAsyncResult BeginConnect(string host, int port, bool ssl, AsyncCallback callback, object state) { if (m_IsDisposed) { throw new ObjectDisposedException(GetType().Name); } if (IsConnected) { throw new InvalidOperationException("TCP client is already connected."); } if (string.IsNullOrEmpty(host)) { throw new ArgumentException("Argument 'host' value may not be null or empty."); } if (port < 1) { throw new ArgumentException("Argument 'port' value must be >= 1."); } BeginConnectHostDelegate asyncMethod = Connect; AsyncResultState asyncState = new AsyncResultState(this, asyncMethod, callback, state); asyncState.SetAsyncResult(asyncMethod.BeginInvoke(host, port, ssl, asyncState.CompletedCallback, null)); return(asyncState); }
/// <summary> /// Starts authentication. /// </summary> /// <param name="userName">User login name.</param> /// <param name="password">Password.</param> /// <param name="tryApop"> If true and POP3 server supports APOP, then APOP is used, otherwise normal login used.</param> /// <param name="callback">Callback to call when the asynchronous operation is complete.</param> /// <param name="state">User data.</param> /// <returns>An IAsyncResult that references the asynchronous operation.</returns> /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception> /// <exception cref="InvalidOperationException">Is raised when POP3 client is not connected or is already authenticated.</exception> public IAsyncResult BeginAuthenticate(string userName, string password, bool tryApop, AsyncCallback callback, object state) { if (IsDisposed) { throw new ObjectDisposedException(GetType().Name); } if (!IsConnected) { throw new InvalidOperationException("You must connect first."); } if (IsAuthenticated) { throw new InvalidOperationException("Session is already authenticated."); } AuthenticateDelegate asyncMethod = Authenticate; AsyncResultState asyncState = new AsyncResultState(this, asyncMethod, callback, state); asyncState.SetAsyncResult(asyncMethod.BeginInvoke(userName, password, tryApop, asyncState.CompletedCallback, null)); return(asyncState); }
/// <summary> /// Starts connection to the specified remote end point. /// </summary> /// <param name="localEP">Local IP end point to use for connect.</param> /// <param name="remoteEP">Remote IP end point where to connect.</param> /// <param name="ssl">Specifies if connects to SSL end point.</param> /// <param name="callback">Callback to call when the connect operation is complete.</param> /// <param name="state">User data.</param> /// <returns>An IAsyncResult that references the asynchronous connection.</returns> /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception> /// <exception cref="InvalidOperationException">Is raised when TCP client is already connected.</exception> /// <exception cref="ArgumentNullException">Is raised when <b>remoteEP</b> is null.</exception> /// <exception cref="ArgumentException">Is raised when any of the arguments has invalid value.</exception> public IAsyncResult BeginConnect(IPEndPoint localEP, IPEndPoint remoteEP, bool ssl, AsyncCallback callback, object state) { if (m_IsDisposed) { throw new ObjectDisposedException(GetType().Name); } if (IsConnected) { throw new InvalidOperationException("TCP client is already connected."); } if (remoteEP == null) { throw new ArgumentNullException("remoteEP"); } BeginConnectEPDelegate asyncMethod = Connect; AsyncResultState asyncState = new AsyncResultState(this, asyncMethod, callback, state); asyncState.SetAsyncResult(asyncMethod.BeginInvoke(localEP, remoteEP, ssl, asyncState.CompletedCallback, null)); return(asyncState); }
/// <summary> /// Ends a pending asynchronous disconnect request. /// </summary> /// <param name="asyncResult">An IAsyncResult that stores state information and any user defined data for this asynchronous operation.</param> /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception> /// <exception cref="ArgumentNullException">Is raised when <b>asyncResult</b> is null.</exception> /// <exception cref="ArgumentException">Is raised when argument <b>asyncResult</b> was not returned by a call to the <b>BeginDisconnect</b> method.</exception> /// <exception cref="InvalidOperationException">Is raised when <b>EndDisconnect</b> was previously called for the asynchronous connection.</exception> public void EndDisconnect(IAsyncResult asyncResult) { if (m_IsDisposed) { throw new ObjectDisposedException(GetType().Name); } if (asyncResult == null) { throw new ArgumentNullException("asyncResult"); } AsyncResultState castedAsyncResult = asyncResult as AsyncResultState; if (castedAsyncResult == null || castedAsyncResult.AsyncObject != this) { throw new ArgumentException( "Argument asyncResult was not returned by a call to the BeginDisconnect method."); } if (castedAsyncResult.IsEndCalled) { throw new InvalidOperationException( "EndDisconnect was previously called for the asynchronous connection."); } castedAsyncResult.IsEndCalled = true; if (castedAsyncResult.AsyncDelegate is DisconnectDelegate) { ((DisconnectDelegate)castedAsyncResult.AsyncDelegate).EndInvoke(castedAsyncResult.AsyncResult); } else { throw new ArgumentException( "Argument asyncResult was not returned by a call to the BeginDisconnect method."); } }
/// <summary> /// Starts switching to SSL. /// </summary> /// <returns>An IAsyncResult that references the asynchronous operation.</returns> /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception> /// <exception cref="InvalidOperationException">Is raised when POP3 client is not connected or is authenticated or is already secure connection.</exception> public IAsyncResult BeginStartTLS(AsyncCallback callback, object state) { if (IsDisposed) { throw new ObjectDisposedException(GetType().Name); } if (!IsConnected) { throw new InvalidOperationException("You must connect first."); } if (IsAuthenticated) { throw new InvalidOperationException( "The STLS command is only valid in non-authenticated state."); } if (IsSecureConnection) { throw new InvalidOperationException("Connection is already secure."); } StartTLSDelegate asyncMethod = StartTLS; AsyncResultState asyncState = new AsyncResultState(this, asyncMethod, callback, state); asyncState.SetAsyncResult(asyncMethod.BeginInvoke(asyncState.CompletedCallback, null)); return(asyncState); }
/// <summary> /// Starts disconnecting connection. /// </summary> /// <param name="callback">Callback to call when the asynchronous operation is complete.</param> /// <param name="state">User data.</param> /// <returns>An IAsyncResult that references the asynchronous disconnect.</returns> /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception> /// <exception cref="InvalidOperationException">Is raised when TCP client is not connected.</exception> public IAsyncResult BeginDisconnect(AsyncCallback callback, object state) { if (m_IsDisposed) { throw new ObjectDisposedException(GetType().Name); } if (!IsConnected) { throw new InvalidOperationException("TCP client is not connected."); } DisconnectDelegate asyncMethod = Disconnect; AsyncResultState asyncState = new AsyncResultState(this, asyncMethod, callback, state); asyncState.SetAsyncResult(asyncMethod.BeginInvoke(asyncState.CompletedCallback, null)); return(asyncState); }
/// <summary> /// Starts sending NOOP command to server. This method can be used for keeping connection alive(not timing out). /// </summary> /// <param name="callback">Callback to call when the asynchronous operation is complete.</param> /// <param name="state">User data.</param> /// <returns>An IAsyncResult that references the asynchronous operation.</returns> /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception> /// <exception cref="InvalidOperationException">Is raised when POP3 client is not connected.</exception> public IAsyncResult BeginNoop(AsyncCallback callback, object state) { if (IsDisposed) { throw new ObjectDisposedException(GetType().Name); } if (!IsConnected) { throw new InvalidOperationException("You must connect first."); } NoopDelegate asyncMethod = Noop; AsyncResultState asyncState = new AsyncResultState(this, asyncMethod, callback, state); asyncState.SetAsyncResult(asyncMethod.BeginInvoke(asyncState.CompletedCallback, null)); return(asyncState); }
/// <summary> /// Starts resetting session. Messages marked for deletion will be unmarked. /// </summary> /// <param name="callback">Callback to call when the asynchronous operation is complete.</param> /// <param name="state">User data.</param> /// <returns>An IAsyncResult that references the asynchronous operation.</returns> /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception> /// <exception cref="InvalidOperationException">Is raised when POP3 client is not connected and authenticated.</exception> public IAsyncResult BeginReset(AsyncCallback callback, object state) { if (IsDisposed) { throw new ObjectDisposedException(GetType().Name); } if (!IsConnected) { throw new InvalidOperationException("You must connect first."); } if (!IsAuthenticated) { throw new InvalidOperationException("The RSET command is only valid in authenticated state."); } ResetDelegate asyncMethod = Reset; AsyncResultState asyncState = new AsyncResultState(this, asyncMethod, callback, state); asyncState.SetAsyncResult(asyncMethod.BeginInvoke(asyncState.CompletedCallback, null)); return(asyncState); }
public IAsyncResult BeginReset(AsyncCallback callback,object state) { if(this.IsDisposed){ throw new ObjectDisposedException(this.GetType().Name); } if(!this.IsConnected){ throw new InvalidOperationException("You must connect first."); } ResetDelegate asyncMethod = new ResetDelegate(this.Reset); AsyncResultState asyncState = new AsyncResultState(this,asyncMethod,callback,state); asyncState.SetAsyncResult(asyncMethod.BeginInvoke(new AsyncCallback(asyncState.CompletedCallback),null)); return asyncState; }
public IAsyncResult BeginRcptTo(string to,SMTP_DSN_Notify notify,string orcpt,AsyncCallback callback,object state) { if(this.IsDisposed){ throw new ObjectDisposedException(this.GetType().Name); } if(!this.IsConnected){ throw new InvalidOperationException("You must connect first."); } RcptToDelegate asyncMethod = new RcptToDelegate(this.RcptTo); AsyncResultState asyncState = new AsyncResultState(this,asyncMethod,callback,state); asyncState.SetAsyncResult(asyncMethod.BeginInvoke(to,notify,orcpt,new AsyncCallback(asyncState.CompletedCallback),null)); return asyncState; }
public IAsyncResult BeginMailFrom(string from,long messageSize,SMTP_DSN_Ret ret,string envid,AsyncCallback callback,object state) { if(this.IsDisposed){ throw new ObjectDisposedException(this.GetType().Name); } if(!this.IsConnected){ throw new InvalidOperationException("You must connect first."); } MailFromDelegate asyncMethod = new MailFromDelegate(this.MailFrom); AsyncResultState asyncState = new AsyncResultState(this,asyncMethod,callback,state); asyncState.SetAsyncResult(asyncMethod.BeginInvoke(from,(int)messageSize,ret,envid,new AsyncCallback(asyncState.CompletedCallback),null)); return asyncState; }
/// <summary> /// Starts switching to SSL. /// </summary> /// <returns>An IAsyncResult that references the asynchronous operation.</returns> /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception> /// <exception cref="InvalidOperationException">Is raised when SMTP client is not connected or is already secure connection.</exception> public IAsyncResult BeginStartTLS(AsyncCallback callback, object state) { if (IsDisposed) { throw new ObjectDisposedException(GetType().Name); } if (!IsConnected) { throw new InvalidOperationException("You must connect first."); } if (IsSecureConnection) { throw new InvalidOperationException("Connection is already secure."); } StartTLSDelegate asyncMethod = StartTLS; AsyncResultState asyncState = new AsyncResultState(this, asyncMethod, callback, state); asyncState.SetAsyncResult(asyncMethod.BeginInvoke(asyncState.CompletedCallback, null)); return asyncState; }
public IAsyncResult BeginAuthenticate(string userName,string password,AsyncCallback callback,object state) { if(this.IsDisposed){ throw new ObjectDisposedException(this.GetType().Name); } if(!this.IsConnected){ throw new InvalidOperationException("You must connect first."); } if(this.IsAuthenticated){ throw new InvalidOperationException("Session is already authenticated."); } AuthenticateDelegate asyncMethod = new AuthenticateDelegate(this.Authenticate); AsyncResultState asyncState = new AsyncResultState(this,asyncMethod,callback,state); asyncState.SetAsyncResult(asyncMethod.BeginInvoke(userName,password,new AsyncCallback(asyncState.CompletedCallback),null)); return asyncState; }
/// <summary> /// Starts connection to the specified remote end point. /// </summary> /// <param name="localEP">Local IP end point to use for connect.</param> /// <param name="remoteEP">Remote IP end point where to connect.</param> /// <param name="ssl">Specifies if connects to SSL end point.</param> /// <param name="callback">Callback to call when the connect operation is complete.</param> /// <param name="state">User data.</param> /// <returns>An IAsyncResult that references the asynchronous connection.</returns> /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception> /// <exception cref="InvalidOperationException">Is raised when TCP client is already connected.</exception> /// <exception cref="ArgumentNullException">Is raised when <b>remoteEP</b> is null.</exception> /// <exception cref="ArgumentException">Is raised when any of the arguments has invalid value.</exception> public IAsyncResult BeginConnect(IPEndPoint localEP, IPEndPoint remoteEP, bool ssl, AsyncCallback callback, object state) { if (m_IsDisposed) { throw new ObjectDisposedException(GetType().Name); } if (IsConnected) { throw new InvalidOperationException("TCP client is already connected."); } if (remoteEP == null) { throw new ArgumentNullException("remoteEP"); } BeginConnectEPDelegate asyncMethod = Connect; AsyncResultState asyncState = new AsyncResultState(this, asyncMethod, callback, state); asyncState.SetAsyncResult(asyncMethod.BeginInvoke(localEP, remoteEP, ssl, asyncState.CompletedCallback, null)); return asyncState; }
/// <summary> /// Starts connection to the specified host. /// </summary> /// <param name="host">Host name or IP address.</param> /// <param name="port">Port to connect.</param> /// <param name="ssl">Specifies if connects to SSL end point.</param> /// <param name="callback">Callback to call when the connect operation is complete.</param> /// <param name="state">User data.</param> /// <returns>An IAsyncResult that references the asynchronous connection.</returns> /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception> /// <exception cref="InvalidOperationException">Is raised when TCP client is already connected.</exception> /// <exception cref="ArgumentException">Is raised when any of the arguments has invalid value.</exception> public IAsyncResult BeginConnect(string host, int port, bool ssl, AsyncCallback callback, object state) { if (m_IsDisposed) { throw new ObjectDisposedException(GetType().Name); } if (IsConnected) { throw new InvalidOperationException("TCP client is already connected."); } if (string.IsNullOrEmpty(host)) { throw new ArgumentException("Argument 'host' value may not be null or empty."); } if (port < 1) { throw new ArgumentException("Argument 'port' value must be >= 1."); } BeginConnectHostDelegate asyncMethod = Connect; AsyncResultState asyncState = new AsyncResultState(this, asyncMethod, callback, state); asyncState.SetAsyncResult(asyncMethod.BeginInvoke(host, port, ssl, asyncState.CompletedCallback, null)); return asyncState; }
/// <summary> /// Starts disconnecting connection. /// </summary> /// <param name="callback">Callback to call when the asynchronous operation is complete.</param> /// <param name="state">User data.</param> /// <returns>An IAsyncResult that references the asynchronous disconnect.</returns> /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception> /// <exception cref="InvalidOperationException">Is raised when TCP client is not connected.</exception> public IAsyncResult BeginDisconnect(AsyncCallback callback, object state) { if (m_IsDisposed) { throw new ObjectDisposedException(GetType().Name); } if (!IsConnected) { throw new InvalidOperationException("TCP client is not connected."); } DisconnectDelegate asyncMethod = Disconnect; AsyncResultState asyncState = new AsyncResultState(this, asyncMethod, callback, state); asyncState.SetAsyncResult(asyncMethod.BeginInvoke(asyncState.CompletedCallback, null)); return asyncState; }
/// <summary> /// Starts sending RCPT TO: command to SMTP server. /// </summary> /// <param name="to">Recipient email address.</param> /// <param name="callback">Callback to call when the asynchronous operation is complete.</param> /// <param name="state">User data.</param> /// <returns>An IAsyncResult that references the asynchronous disconnect.</returns> /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception> /// <exception cref="InvalidOperationException">Is raised when SMTP client is not connected.</exception> public IAsyncResult BeginRcptTo(string to, AsyncCallback callback, object state) { if (IsDisposed) { throw new ObjectDisposedException(GetType().Name); } if (!IsConnected) { throw new InvalidOperationException("You must connect first."); } RcptToDelegate asyncMethod = RcptTo; AsyncResultState asyncState = new AsyncResultState(this, asyncMethod, callback, state); asyncState.SetAsyncResult(asyncMethod.BeginInvoke(to, asyncState.CompletedCallback, null)); return asyncState; }
public IAsyncResult BeginSendMessage(Stream message,AsyncCallback callback,object state) { if(this.IsDisposed){ throw new ObjectDisposedException(this.GetType().Name); } if(!this.IsConnected){ throw new InvalidOperationException("You must connect first."); } if(message == null){ throw new ArgumentNullException("message"); } SendMessageDelegate asyncMethod = new SendMessageDelegate(this.SendMessage); AsyncResultState asyncState = new AsyncResultState(this,asyncMethod,callback,state); asyncState.SetAsyncResult(asyncMethod.BeginInvoke(message,new AsyncCallback(asyncState.CompletedCallback),null)); return asyncState; }
/// <summary> /// Starts resetting session. Messages marked for deletion will be unmarked. /// </summary> /// <param name="callback">Callback to call when the asynchronous operation is complete.</param> /// <param name="state">User data.</param> /// <returns>An IAsyncResult that references the asynchronous operation.</returns> /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception> /// <exception cref="InvalidOperationException">Is raised when POP3 client is not connected and authenticated.</exception> public IAsyncResult BeginReset(AsyncCallback callback, object state) { if (IsDisposed) { throw new ObjectDisposedException(GetType().Name); } if (!IsConnected) { throw new InvalidOperationException("You must connect first."); } if (!IsAuthenticated) { throw new InvalidOperationException("The RSET command is only valid in authenticated state."); } ResetDelegate asyncMethod = Reset; AsyncResultState asyncState = new AsyncResultState(this, asyncMethod, callback, state); asyncState.SetAsyncResult(asyncMethod.BeginInvoke(asyncState.CompletedCallback, null)); return asyncState; }
public IAsyncResult BeginStartTLS(AsyncCallback callback,object state) { if(this.IsDisposed){ throw new ObjectDisposedException(this.GetType().Name); } if(!this.IsConnected){ throw new InvalidOperationException("You must connect first."); } if(this.IsAuthenticated){ throw new InvalidOperationException("The STLS command is only valid in non-authenticated state."); } if(this.IsSecureConnection){ throw new InvalidOperationException("Connection is already secure."); } StartTLSDelegate asyncMethod = new StartTLSDelegate(this.StartTLS); AsyncResultState asyncState = new AsyncResultState(this,asyncMethod,callback,state); asyncState.SetAsyncResult(asyncMethod.BeginInvoke(new AsyncCallback(asyncState.CompletedCallback),null)); return asyncState; }
public static IAsyncResult BeginGetDomainHosts(string domain,AsyncCallback callback,object state) { if(domain == null){ throw new ArgumentNullException("domain"); } if(string.IsNullOrEmpty(domain)){ throw new ArgumentException("Invalid argument 'domain' value, you need to specify domain value."); } GetDomainHostsDelegate asyncMethod = new GetDomainHostsDelegate(GetDomainHosts); AsyncResultState asyncState = new AsyncResultState(null,asyncMethod,callback,state); asyncState.SetAsyncResult(asyncMethod.BeginInvoke(domain,new AsyncCallback(asyncState.CompletedCallback),null)); return asyncState; }
/// <summary> /// Starts sending MAIL FROM: command to SMTP server. /// </summary> /// <param name="from">Sender email address reported to SMTP server.</param> /// <param name="messageSize">Sendable message size in bytes, -1 if message size unknown.</param> /// <param name="callback">Callback to call when the asynchronous operation is complete.</param> /// <param name="state">User data.</param> /// <returns>An IAsyncResult that references the asynchronous disconnect.</returns> /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception> /// <exception cref="InvalidOperationException">Is raised when SMTP client is not connected.</exception> public IAsyncResult BeginMailFrom(string from, long messageSize, AsyncCallback callback, object state) { if (IsDisposed) { throw new ObjectDisposedException(GetType().Name); } if (!IsConnected) { throw new InvalidOperationException("You must connect first."); } MailFromDelegate asyncMethod = MailFrom; AsyncResultState asyncState = new AsyncResultState(this, asyncMethod, callback, state); asyncState.SetAsyncResult(asyncMethod.BeginInvoke(from, messageSize, asyncState.CompletedCallback, null)); return asyncState; }