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 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); } } }
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); } }
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); } } }
internal IAsyncResult BeginSendMail(MailAddress sender, MailAddressCollection recipients, string deliveryNotify, bool allowUnicode, AsyncCallback callback, object state) { if (sender == null) { throw new ArgumentNullException(nameof(sender)); } if (recipients == null) { throw new ArgumentNullException(nameof(recipients)); } if (GlobalLog.IsEnabled && recipients.Count > 0) { GlobalLog.Assert("SmtpTransport::BeginSendMail()|recepients.Count <= 0"); } SendMailAsyncResult result = new SendMailAsyncResult(_connection, sender, recipients, allowUnicode, _connection.DSNEnabled ? deliveryNotify : null, callback, state); result.Send(); return(result); }
void SendMailCallback(IAsyncResult result) { GlobalLog.Enter("SmtpClient#" + ValidationHelper.HashString(this) + "::SendMailCallback"); try { writer = transport.EndSendMail(result); // If some recipients failed but not others, send the e-mail anyways, 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); GlobalLog.Leave("SmtpClient#" + ValidationHelper.HashString(this) + "::SendMailCallback"); return; } try { if (cancelled) { Complete(null, result); } else { message.BeginSend(writer, DeliveryMethod != SmtpDeliveryMethod.Network, ServerSupportsEai, new AsyncCallback(SendMessageCallback), result.AsyncState); } } catch (Exception e) { Complete(e, result); } GlobalLog.Leave("SmtpClient#" + ValidationHelper.HashString(this) + "::SendMailCallback"); }
internal MailWriter EndSendMail(IAsyncResult result) { try { return(SendMailAsyncResult.End(result)); } finally { } }
internal static MailWriter End(IAsyncResult result) { SendMailAsyncResult result2 = (SendMailAsyncResult)result; object obj2 = result2.InternalWaitForCompletion(); if (obj2 is Exception) { throw ((Exception)obj2); } return(new MailWriter(result2.stream)); }
internal IAsyncResult BeginSendMail(MailAddress sender, MailAddressCollection recipients, string deliveryNotify, AsyncCallback callback, object state) { if (sender == null) { throw new ArgumentNullException("sender"); } if (recipients == null) { throw new ArgumentNullException("recipients"); } SendMailAsyncResult result = new SendMailAsyncResult(this.connection, sender.SmtpAddress, recipients, this.connection.DSNEnabled ? deliveryNotify : null, callback, state); result.Send(); return result; }
internal IAsyncResult BeginSendMail(MailAddress sender, MailAddressCollection recipients, string deliveryNotify, AsyncCallback callback, object state) { if (sender == null) { throw new ArgumentNullException("sender"); } if (recipients == null) { throw new ArgumentNullException("recipients"); } SendMailAsyncResult result = new SendMailAsyncResult(this.connection, sender.SmtpAddress, recipients, this.connection.DSNEnabled ? deliveryNotify : null, callback, state); result.Send(); return(result); }
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); } } }
internal static MailWriter End(IAsyncResult result) { SendMailAsyncResult thisPtr = (SendMailAsyncResult)result; object sendMailResult = thisPtr.InternalWaitForCompletion(); // Note the difference between the singular and plural FailedRecipient exceptions. // Only fail immediately if we couldn't send to any recipients. if ((sendMailResult is Exception e) && (!(sendMailResult is SmtpFailedRecipientException) || ((SmtpFailedRecipientException)sendMailResult).fatal)) { ExceptionDispatchInfo.Throw(e); } return(new MailWriter(thisPtr._stream)); }
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); } } }
internal IAsyncResult BeginSendMail(MailAddress sender, MailAddressCollection recipients, string deliveryNotify, bool allowUnicode, AsyncCallback callback, object state) { if (sender == null) { throw new ArgumentNullException(nameof(sender)); } if (recipients == null) { throw new ArgumentNullException(nameof(recipients)); } SendMailAsyncResult result = new SendMailAsyncResult(_connection, sender, recipients, allowUnicode, _connection.DSNEnabled ? deliveryNotify : null, callback, state); result.Send(); return(result); }
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); } } }
internal IAsyncResult BeginSendMail(MailAddress sender, MailAddressCollection recipients, string deliveryNotify, bool allowUnicode, AsyncCallback callback, object state) { if (sender == null) { throw new ArgumentNullException("sender"); } if (recipients == null) { throw new ArgumentNullException("recipients"); } GlobalLog.Assert(recipients.Count > 0, "SmtpTransport::BeginSendMail()|recepients.Count <= 0"); SendMailAsyncResult result = new SendMailAsyncResult(connection, sender, recipients, allowUnicode, connection.DSNEnabled ? deliveryNotify : null, callback, state); result.Send(); return result; }
internal IAsyncResult BeginSendMail(MailAddress sender, MailAddressCollection recipients, string deliveryNotify, bool allowUnicode, AsyncCallback callback, object state) { if (sender == null) { throw new ArgumentNullException(nameof(sender)); } if (recipients == null) { throw new ArgumentNullException(nameof(recipients)); } SendMailAsyncResult result = new SendMailAsyncResult(_connection, sender, recipients, allowUnicode, _connection.DSNEnabled ? deliveryNotify : null, callback, state); result.Send(); return result; }
protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state) { MailMessage message = new MailMessage(); message.From = this.From.Get(context); if (TestMailTo.Expression == null) { foreach (MailAddress address in this.To.Get(context)) { message.To.Add(address); } MailAddressCollection ccList = this.CC.Get(context); if (ccList != null) { foreach (MailAddress address in ccList) { message.CC.Add(address); } } MailAddressCollection bccList = this.Bcc.Get(context); if (bccList != null) { foreach (MailAddress address in bccList) { message.Bcc.Add(address); } } } else { message.To.Add(TestMailTo.Get(context)); } Collection<Attachment> attachments = this.Attachments.Get(context); if (attachments != null) { foreach (Attachment attachment in attachments) { message.Attachments.Add(attachment); } } if (!string.IsNullOrEmpty(this.BodyTemplateFilePath)) { LoadBodyTemplate(context); } if ((this.Tokens.Get(context) != null) && (this.Tokens.Get(context).Count > 0)) { ReplaceTokensInBody(context); } if (this.TestMailTo.Expression != null) { AddTestInformationToBody(context); } message.Subject = this.Subject.Get(context); message.Body = this.Body; SmtpClient client = new SmtpClient(); client.Host = this.Host; client.Port = this.Port; client.EnableSsl = this.EnableSsl; if (string.IsNullOrEmpty(this.UserName)) { client.UseDefaultCredentials = true; } else { client.UseDefaultCredentials = false; client.Credentials = new NetworkCredential(this.UserName, this.Password); } if (!string.IsNullOrEmpty(this.TestDropPath)) { WriteMailInTestDropPath(context); } var sendMailAsyncResult = new SendMailAsyncResult(client, message, callback, state); context.UserState = sendMailAsyncResult; return sendMailAsyncResult; }