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

GetFailedRecipientException() private method

private GetFailedRecipientException ( ) : System.Net.Mail.SmtpFailedRecipientException
return System.Net.Mail.SmtpFailedRecipientException
        internal SmtpFailedRecipientException GetFailedRecipientException()
        {
            if (_failedRecipientExceptions.Count == 1)
            {
                return (SmtpFailedRecipientException)_failedRecipientExceptions[0];
            }
            else if (_failedRecipientExceptions.Count > 1)
            {
                // Aggregate exception, multiple failures
                return new SmtpFailedRecipientsException(_failedRecipientExceptions, false);
            }
            return null;
        }
    }

Usage Example

Example #1
0
        private void SendMailCallback(IAsyncResult result)
        {
            try
            {
                _writer = _transport.EndSendMail(result);
                // If some recipients failed but not others, send the e-mail anyway, but then return the
                // "Non-fatal" exception reporting the failures.  The sync code path does it this way.
                // Fatal exceptions would have thrown above at transport.EndSendMail(...)
                SendMailAsyncResult sendResult = (SendMailAsyncResult)result;
                // Save these and throw them later in SendMessageCallback, after the message has sent.
                _failedRecipientException = sendResult.GetFailedRecipientException();
            }
            catch (Exception e)
            {
                Complete(e, result);
                return;
            }

            try
            {
                if (_cancelled)
                {
                    Complete(null, result);
                }
                else
                {
                    _message !.BeginSend(_writer, DeliveryMethod != SmtpDeliveryMethod.Network,
                                         IsUnicodeSupported(), new AsyncCallback(SendMessageCallback), result.AsyncState !);
                }
            }
            catch (Exception e)
            {
                Complete(e, result);
            }
        }
All Usage Examples Of System.Net.Mail.SendMailAsyncResult::GetFailedRecipientException