Пример #1
0
        private static void SendToCollectionCompleted(IAsyncResult result)
        {
            if (!result.CompletedSynchronously)
            {
                SendMailAsyncResult thisPtr = (SendMailAsyncResult)result.AsyncState !;
                try
                {
                    string response;
                    if (!RecipientCommand.EndSend(result, out response))
                    {
                        thisPtr._failedRecipientExceptions.Add(
                            new SmtpFailedRecipientException(thisPtr._connection.Reader !.StatusCode,
                                                             thisPtr._toCollection[thisPtr._toIndex - 1].GetSmtpAddress(thisPtr._allowUnicode),
                                                             response));

                        if (thisPtr._failedRecipientExceptions.Count == thisPtr._toCollection.Count)
                        {
                            SmtpFailedRecipientException exception = thisPtr._toCollection.Count == 1 ?
                                                                     (SmtpFailedRecipientException)thisPtr._failedRecipientExceptions[0] :
                                                                     new SmtpFailedRecipientsException(thisPtr._failedRecipientExceptions, true);
                            exception.fatal = true;
                            thisPtr.InvokeCallback(exception);
                            return;
                        }
                    }
                    thisPtr.SendToCollection();
                }
                catch (Exception e)
                {
                    thisPtr.InvokeCallback(e);
                }
            }
        }
Пример #2
0
 private static void SendDataCompleted(IAsyncResult result)
 {
     if (!result.CompletedSynchronously)
     {
         SendMailAsyncResult thisPtr = (SendMailAsyncResult)result.AsyncState;
         try
         {
             DataCommand.EndSend(result);
             thisPtr._stream = thisPtr._connection.GetClosableStream();
             if (thisPtr._failedRecipientExceptions.Count > 1)
             {
                 thisPtr.InvokeCallback(new SmtpFailedRecipientsException(thisPtr._failedRecipientExceptions, thisPtr._failedRecipientExceptions.Count == thisPtr._toCollection.Count));
             }
             else if (thisPtr._failedRecipientExceptions.Count == 1)
             {
                 thisPtr.InvokeCallback(thisPtr._failedRecipientExceptions[0]);
             }
             else
             {
                 thisPtr.InvokeCallback();
             }
         }
         catch (Exception e)
         {
             thisPtr.InvokeCallback(e);
         }
     }
 }
 private static void SendDataCompleted(IAsyncResult result)
 {
     if (!result.CompletedSynchronously)
     {
         SendMailAsyncResult asyncState = (SendMailAsyncResult)result.AsyncState;
         try
         {
             DataCommand.EndSend(result);
             asyncState.stream = asyncState.connection.GetClosableStream();
             if (asyncState.failedRecipientExceptions.Count > 1)
             {
                 asyncState.InvokeCallback(new SmtpFailedRecipientsException(asyncState.failedRecipientExceptions, asyncState.failedRecipientExceptions.Count == asyncState.toCollection.Count));
             }
             else if (asyncState.failedRecipientExceptions.Count == 1)
             {
                 asyncState.InvokeCallback(asyncState.failedRecipientExceptions[0]);
             }
             else
             {
                 asyncState.InvokeCallback();
             }
         }
         catch (Exception exception)
         {
             asyncState.InvokeCallback(exception);
         }
     }
 }
 private static void SendToCollectionCompleted(IAsyncResult result)
 {
     if (!result.CompletedSynchronously)
     {
         SendMailAsyncResult asyncState = (SendMailAsyncResult)result.AsyncState;
         try
         {
             string str;
             if (!RecipientCommand.EndSend(result, out str))
             {
                 asyncState.failedRecipientExceptions.Add(new SmtpFailedRecipientException(asyncState.connection.Reader.StatusCode, asyncState.toCollection[asyncState.toIndex - 1].SmtpAddress, str));
                 if (asyncState.failedRecipientExceptions.Count == asyncState.toCollection.Count)
                 {
                     SmtpFailedRecipientException exception = null;
                     if (asyncState.toCollection.Count == 1)
                     {
                         exception = (SmtpFailedRecipientException)asyncState.failedRecipientExceptions[0];
                     }
                     else
                     {
                         exception = new SmtpFailedRecipientsException(asyncState.failedRecipientExceptions, true);
                     }
                     exception.fatal = true;
                     asyncState.InvokeCallback(exception);
                     return;
                 }
             }
             if (asyncState.SendToCollection())
             {
                 asyncState.SendData();
             }
         }
         catch (Exception exception2)
         {
             asyncState.InvokeCallback(exception2);
         }
     }
 }
 private static void SendToCompleted(IAsyncResult result)
 {
     if (!result.CompletedSynchronously)
     {
         SendMailAsyncResult asyncState = (SendMailAsyncResult)result.AsyncState;
         try
         {
             string str;
             if (RecipientCommand.EndSend(result, out str))
             {
                 asyncState.SendData();
             }
             else
             {
                 asyncState.InvokeCallback(new SmtpFailedRecipientException(asyncState.connection.Reader.StatusCode, asyncState.to, str));
             }
         }
         catch (Exception exception)
         {
             asyncState.InvokeCallback(exception);
         }
     }
 }
Пример #6
0
 private static void SendMailFromCompleted(IAsyncResult result)
 {
     if (!result.CompletedSynchronously)
     {
         SendMailAsyncResult thisPtr = (SendMailAsyncResult)result.AsyncState;
         try
         {
             MailCommand.EndSend(result);
             thisPtr.SendToCollection();
         }
         catch (Exception e)
         {
             thisPtr.InvokeCallback(e);
         }
     }
 }
 private static void SendMailFromCompleted(IAsyncResult result)
 {
     if (!result.CompletedSynchronously)
     {
         SendMailAsyncResult asyncState = (SendMailAsyncResult)result.AsyncState;
         try
         {
             MailCommand.EndSend(result);
             asyncState.SendTo();
         }
         catch (Exception exception)
         {
             asyncState.InvokeCallback(exception);
         }
     }
 }