Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ SendAsync() [1/2]

void System.Net.Mail.SmtpClient.SendAsync ( MailMessage message,
object? userToken )
inline

Definition at line 542 of file SmtpClient.cs.

543 {
544 if (_disposed)
545 {
546 throw new ObjectDisposedException(GetType().FullName);
547 }
548 try
549 {
550 if (InCall)
551 {
553 }
554 if (message == null)
555 {
556 throw new ArgumentNullException("message");
557 }
558 if (DeliveryMethod == SmtpDeliveryMethod.Network)
559 {
561 }
562 _recipients = new MailAddressCollection();
563 if (message.From == null)
564 {
566 }
567 if (message.To != null)
568 {
569 foreach (MailAddress item in message.To)
570 {
572 }
573 }
574 if (message.Bcc != null)
575 {
576 foreach (MailAddress item2 in message.Bcc)
577 {
578 _recipients.Add(item2);
579 }
580 }
581 if (message.CC != null)
582 {
583 foreach (MailAddress item3 in message.CC)
584 {
585 _recipients.Add(item3);
586 }
587 }
588 if (_recipients.Count == 0)
589 {
591 }
592 InCall = true;
593 _cancelled = false;
594 _message = message;
595 string pickupDirectoryLocation = PickupDirectoryLocation;
596 _transport.IdentityRequired = Credentials != null && (Credentials == CredentialCache.DefaultNetworkCredentials || !(Credentials is CredentialCache cache) || IsSystemNetworkCredentialInCache(cache));
598 switch (DeliveryMethod)
599 {
600 case SmtpDeliveryMethod.PickupDirectoryFromIis:
601 throw new NotSupportedException(System.SR.SmtpGetIisPickupDirectoryNotSupported);
602 case SmtpDeliveryMethod.SpecifiedPickupDirectory:
603 {
604 if (EnableSsl)
605 {
606 throw new SmtpException(System.SR.SmtpPickupDirectoryDoesnotSupportSsl);
607 }
608 _writer = GetFileMailWriter(pickupDirectoryLocation);
609 bool allowUnicode = IsUnicodeSupported();
610 ValidateUnicodeRequirement(message, _recipients, allowUnicode);
611 message.Send(_writer, sendEnvelope: true, allowUnicode);
612 if (_writer != null)
613 {
614 _writer.Close();
615 }
616 AsyncCompletedEventArgs arg = new AsyncCompletedEventArgs(null, cancelled: false, _asyncOp.UserSuppliedState);
617 InCall = false;
619 return;
620 }
621 }
623 lock (_operationCompletedResult.StartPostingAsyncOp())
624 {
625 if (System.Net.NetEventSource.Log.IsEnabled())
626 {
627 System.Net.NetEventSource.Info(this, $"Calling BeginConnect. Transport: {_transport}", "SendAsync");
628 }
630 _operationCompletedResult.FinishPostingAsyncOp();
631 }
632 }
633 catch (Exception ex)
634 {
635 InCall = false;
636 if (System.Net.NetEventSource.Log.IsEnabled())
637 {
638 System.Net.NetEventSource.Error(this, ex, "SendAsync");
639 }
640 if (ex is SmtpFailedRecipientException && !((SmtpFailedRecipientException)ex).fatal)
641 {
642 throw;
643 }
644 Abort();
645 if (ex is SecurityException || ex is AuthenticationException || ex is SmtpException)
646 {
647 throw;
648 }
649 throw new SmtpException(System.SR.SmtpSendMailFailure, ex);
650 }
651 }
static AsyncOperation CreateOperation(object? userSuppliedState)
void PostOperationCompleted(SendOrPostCallback d, object? arg)
override void Close()
Definition MailWriter.cs:31
SendOrPostCallback _onSendCompletedDelegate
Definition SmtpClient.cs:48
SmtpDeliveryMethod DeliveryMethod
void ValidateUnicodeRequirement(MailMessage message, MailAddressCollection recipients, bool allowUnicode)
void ConnectCallback(IAsyncResult result)
MailWriter GetFileMailWriter(string pickupDirectory)
System.Net.ContextAwareResult _operationCompletedResult
Definition SmtpClient.cs:52
bool IsSystemNetworkCredentialInCache(CredentialCache cache)
static readonly AsyncCallback s_contextSafeCompleteCallback
Definition SmtpClient.cs:56
AsyncOperation _asyncOp
Definition SmtpClient.cs:54
MailAddressCollection _recipients
Definition SmtpClient.cs:46
ICredentialsByHost? Credentials
IAsyncResult BeginGetConnection(System.Net.ContextAwareResult outerResult, AsyncCallback callback, object state, string host, int port)
static readonly System.Net.NetEventSource Log
static void Info(object thisOrContextObject, FormattableString formattableString=null, [CallerMemberName] string memberName=null)
static void Error(object thisOrContextObject, FormattableString formattableString, [CallerMemberName] string memberName=null)
static string net_inasync
Definition SR.cs:64
static string SmtpGetIisPickupDirectoryNotSupported
Definition SR.cs:172
static string SmtpFromRequired
Definition SR.cs:82
static string SmtpSendMailFailure
Definition SR.cs:114
static string SmtpRecipientRequired
Definition SR.cs:112
static string SmtpPickupDirectoryDoesnotSupportSsl
Definition SR.cs:108
Definition SR.cs:7

References System.Net.Mail.SmtpClient._asyncOp, System.Net.Mail.SmtpClient._cancelled, System.Net.Mail.SmtpClient._disposed, System.Net.Mail.SmtpClient._message, System.Net.Mail.SmtpClient._onSendCompletedDelegate, System.Net.Mail.SmtpClient._operationCompletedResult, System.Net.Mail.SmtpClient._recipients, System.Net.Mail.SmtpClient._transport, System.Net.Mail.SmtpClient._writer, System.Net.Mail.SmtpClient.Abort(), System.Net.Mail.MailAddressCollection.Add(), System.Net.Mail.MailMessage.Bcc, System.Net.Mail.SmtpTransport.BeginGetConnection(), System.Net.Mail.MailMessage.CC, System.Net.Mail.SmtpClient.CheckHostAndPort(), System.Net.Mail.MailWriter.Close(), System.Net.Mail.SmtpClient.ConnectCallback(), System.Collections.ObjectModel.Collection< T >.Count, System.ComponentModel.AsyncOperationManager.CreateOperation(), System.Net.Mail.SmtpClient.Credentials, System.Net.Mail.SmtpClient.DeliveryMethod, System.Net.Mail.SmtpClient.EnableSsl, System.Net.NetEventSource.Error(), System.Net.Mail.MailMessage.From, System.FullName, System.Net.Mail.SmtpClient.GetFileMailWriter(), System.Net.Mail.SmtpClient.Host, System.Net.Mail.SmtpTransport.IdentityRequired, System.Net.Mail.SmtpClient.InCall, System.Net.NetEventSource.Info(), System.Net.Mail.SmtpClient.IsSystemNetworkCredentialInCache(), System.Net.Mail.SmtpClient.IsUnicodeSupported(), System.item, System.Net.NetEventSource.Log, System.SR.net_inasync, System.Net.Mail.SmtpClient.PickupDirectoryLocation, System.Net.Mail.SmtpClient.Port, System.ComponentModel.AsyncOperation.PostOperationCompleted(), System.Net.Mail.SmtpClient.s_contextSafeCompleteCallback, System.Net.Mail.MailMessage.Send(), System.SR.SmtpFromRequired, System.SR.SmtpGetIisPickupDirectoryNotSupported, System.SR.SmtpPickupDirectoryDoesnotSupportSsl, System.SR.SmtpRecipientRequired, System.SR.SmtpSendMailFailure, System.Net.Mail.MailMessage.To, System.ComponentModel.AsyncOperation.UserSuppliedState, and System.Net.Mail.SmtpClient.ValidateUnicodeRequirement().