System.Net.Mail.SendMailAsyncResult.SendToCollection C# (CSharp) Method

SendToCollection() private method

private SendToCollection ( ) : void
return void
        private void SendToCollection()
        {
            while (_toIndex < _toCollection.Count)
            {
                MultiAsyncResult result = (MultiAsyncResult)RecipientCommand.BeginSend(_connection,
                    _toCollection[_toIndex++].GetSmtpAddress(_allowUnicode) + _deliveryNotify,
                    s_sendToCollectionCompleted, this);
                if (!result.CompletedSynchronously)
                {
                    return;
                }
                string response;
                if (!RecipientCommand.EndSend(result, out response))
                {
                    _failedRecipientExceptions.Add(new SmtpFailedRecipientException(_connection.Reader.StatusCode,
                        _toCollection[_toIndex - 1].GetSmtpAddress(_allowUnicode), response));
                }
            }
            SendData();
        }

Usage Example

Example #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);
                }
            }
        }
All Usage Examples Of System.Net.Mail.SendMailAsyncResult::SendToCollection