예제 #1
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);
         }
     }
 }
예제 #2
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 = null;
                            if (thisPtr._toCollection.Count == 1)
                            {
                                exception = (SmtpFailedRecipientException)thisPtr._failedRecipientExceptions[0];
                            }
                            else
                            {
                                exception = new SmtpFailedRecipientsException(thisPtr._failedRecipientExceptions, true);
                            }
                            exception.fatal = true;
                            thisPtr.InvokeCallback(exception);
                            return;
                        }
                    }
                    thisPtr.SendToCollection();
                }
                catch (Exception e)
                {
                    thisPtr.InvokeCallback(e);
                }
            }
        }
예제 #3
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);
         }
     }
 }