using System; using System.Collections.Generic; using System.ComponentModel; using System.Globalization; using System.IO; using System.Net.Mime; using System.Net.Security; using System.Net.Sockets; using System.Security.Authentication; using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading; namespace System.Net.Mail { /// Allows applications to send e-mail by using the Simple Mail Transfer Protocol (SMTP). // Token: 0x02000143 RID: 323 public class SmtpClient { /// Initializes a new instance of the class by using configuration file settings. // Token: 0x06000B05 RID: 2821 RVA: 0x00020C80 File Offset: 0x0001EE80 public SmtpClient() : this(null, 0) { } /// Initializes a new instance of the class that sends e-mail by using the specified SMTP server. /// A that contains the name or IP address of the host computer used for SMTP transactions. // Token: 0x06000B06 RID: 2822 RVA: 0x00020C8C File Offset: 0x0001EE8C public SmtpClient(string host) : this(host, 0) { } /// Initializes a new instance of the class that sends e-mail by using the specified SMTP server and port. /// A that contains the name or IP address of the host used for SMTP transactions. /// An greater than zero that contains the port to be used on . /// /// cannot be less than zero. // Token: 0x06000B07 RID: 2823 RVA: 0x00020C98 File Offset: 0x0001EE98 public SmtpClient(string host, int port) { if (!string.IsNullOrEmpty(host)) { this.host = host; } if (port != 0) { this.port = port; } } /// Occurs when an asynchronous e-mail send operation completes. // Token: 0x14000022 RID: 34 // (add) Token: 0x06000B08 RID: 2824 RVA: 0x00020D04 File Offset: 0x0001EF04 // (remove) Token: 0x06000B09 RID: 2825 RVA: 0x00020D20 File Offset: 0x0001EF20 public event SendCompletedEventHandler SendCompleted; /// Specify which certificates should be used to establish the Secure Sockets Layer (SSL) connection. /// An , holding one or more client certificates. The default value is derived from the mail configuration attributes in a configuration file. // Token: 0x170002CD RID: 717 // (get) Token: 0x06000B0A RID: 2826 RVA: 0x00020D3C File Offset: 0x0001EF3C [global::System.MonoTODO("Client certificates not used")] public global::System.Security.Cryptography.X509Certificates.X509CertificateCollection ClientCertificates { get { if (this.clientCertificates == null) { this.clientCertificates = new global::System.Security.Cryptography.X509Certificates.X509CertificateCollection(); } return this.clientCertificates; } } /// Gets or sets the Service Provider Name (SPN) to use for authentication when using extended protection. /// A that specifies the SPN to use for extended protection. The default value for this SPN is of the form "SMTPSVC/<host>" where <host> is the hostname of the SMTP mail server. // Token: 0x170002CE RID: 718 // (get) Token: 0x06000B0B RID: 2827 RVA: 0x00020D5C File Offset: 0x0001EF5C // (set) Token: 0x06000B0C RID: 2828 RVA: 0x00020D64 File Offset: 0x0001EF64 private string TargetName { get; set; } /// Gets or sets the credentials used to authenticate the sender. /// An that represents the credentials to use for authentication; or null if no credentials have been specified. /// You cannot change the value of this property when an email is being sent. // Token: 0x170002CF RID: 719 // (get) Token: 0x06000B0D RID: 2829 RVA: 0x00020D70 File Offset: 0x0001EF70 // (set) Token: 0x06000B0E RID: 2830 RVA: 0x00020D78 File Offset: 0x0001EF78 public ICredentialsByHost Credentials { get { return this.credentials; } set { this.CheckState(); this.credentials = value; } } /// Specifies how outgoing email messages will be handled. /// An that indicates how email messages are delivered. // Token: 0x170002D0 RID: 720 // (get) Token: 0x06000B0F RID: 2831 RVA: 0x00020D88 File Offset: 0x0001EF88 // (set) Token: 0x06000B10 RID: 2832 RVA: 0x00020D90 File Offset: 0x0001EF90 public SmtpDeliveryMethod DeliveryMethod { get { return this.deliveryMethod; } set { this.CheckState(); this.deliveryMethod = value; } } /// Specify whether the uses Secure Sockets Layer (SSL) to encrypt the connection. /// true if the uses SSL; otherwise, false. The default is false. // Token: 0x170002D1 RID: 721 // (get) Token: 0x06000B11 RID: 2833 RVA: 0x00020DA0 File Offset: 0x0001EFA0 // (set) Token: 0x06000B12 RID: 2834 RVA: 0x00020DA8 File Offset: 0x0001EFA8 public bool EnableSsl { get { return this.enableSsl; } set { this.CheckState(); this.enableSsl = value; } } /// Gets or sets the name or IP address of the host used for SMTP transactions. /// A that contains the name or IP address of the computer to use for SMTP transactions. /// The value specified for a set operation is null. /// The value specified for a set operation is equal to (""). /// You cannot change the value of this property when an email is being sent. // Token: 0x170002D2 RID: 722 // (get) Token: 0x06000B13 RID: 2835 RVA: 0x00020DB8 File Offset: 0x0001EFB8 // (set) Token: 0x06000B14 RID: 2836 RVA: 0x00020DC0 File Offset: 0x0001EFC0 public string Host { get { return this.host; } set { if (value == null) { throw new ArgumentNullException("value"); } if (value.Length == 0) { throw new ArgumentException("An empty string is not allowed.", "value"); } this.CheckState(); this.host = value; } } /// Gets or sets the folder where applications save mail messages to be processed by the local SMTP server. /// A that specifies the pickup directory for mail messages. // Token: 0x170002D3 RID: 723 // (get) Token: 0x06000B15 RID: 2837 RVA: 0x00020DFC File Offset: 0x0001EFFC // (set) Token: 0x06000B16 RID: 2838 RVA: 0x00020E04 File Offset: 0x0001F004 public string PickupDirectoryLocation { get { return this.pickupDirectoryLocation; } set { this.pickupDirectoryLocation = value; } } /// Gets or sets the port used for SMTP transactions. /// An that contains the port number on the SMTP host. The default value is 25. /// The value specified for a set operation is less than or equal to zero. /// You cannot change the value of this property when an email is being sent. // Token: 0x170002D4 RID: 724 // (get) Token: 0x06000B17 RID: 2839 RVA: 0x00020E10 File Offset: 0x0001F010 // (set) Token: 0x06000B18 RID: 2840 RVA: 0x00020E18 File Offset: 0x0001F018 public int Port { get { return this.port; } set { if (value <= 0) { throw new ArgumentOutOfRangeException("value"); } this.CheckState(); this.port = value; } } /// Gets the network connection used to transmit the e-mail message. /// A that connects to the property used for SMTP. /// /// is null or the empty string ("").-or- is zero. // Token: 0x170002D5 RID: 725 // (get) Token: 0x06000B19 RID: 2841 RVA: 0x00020E3C File Offset: 0x0001F03C [global::System.MonoTODO] public ServicePoint ServicePoint { get { throw new NotImplementedException(); } } /// Gets or sets a value that specifies the amount of time after which a synchronous call times out. /// An that specifies the time-out value in milliseconds. The default value is 100,000 (100 seconds). /// The value specified for a set operation was less than zero. /// You cannot change the value of this property when an email is being sent. // Token: 0x170002D6 RID: 726 // (get) Token: 0x06000B1A RID: 2842 RVA: 0x00020E44 File Offset: 0x0001F044 // (set) Token: 0x06000B1B RID: 2843 RVA: 0x00020E4C File Offset: 0x0001F04C public int Timeout { get { return this.timeout; } set { if (value < 0) { throw new ArgumentOutOfRangeException("value"); } this.CheckState(); this.timeout = value; } } /// Gets or sets a value that controls whether the are sent with requests. /// true if the default credentials are used; otherwise false. The default value is false. /// You cannot change the value of this property when an e-mail is being sent. // Token: 0x170002D7 RID: 727 // (get) Token: 0x06000B1C RID: 2844 RVA: 0x00020E70 File Offset: 0x0001F070 // (set) Token: 0x06000B1D RID: 2845 RVA: 0x00020E74 File Offset: 0x0001F074 public bool UseDefaultCredentials { get { return false; } [global::System.MonoNotSupported("no DefaultCredential support in Mono")] set { if (value) { throw new NotImplementedException("Default credentials are not supported"); } this.CheckState(); } } // Token: 0x06000B1E RID: 2846 RVA: 0x00020E90 File Offset: 0x0001F090 private void CheckState() { if (this.messageInProcess != null) { throw new InvalidOperationException("Cannot set Timeout while Sending a message"); } } // Token: 0x06000B1F RID: 2847 RVA: 0x00020EA8 File Offset: 0x0001F0A8 private static string EncodeAddress(MailAddress address) { string text = global::System.Net.Mime.ContentType.EncodeSubjectRFC2047(address.DisplayName, Encoding.UTF8); return string.Concat(new string[] { "\"", text, "\" <", address.Address, ">" }); } // Token: 0x06000B20 RID: 2848 RVA: 0x00020EF8 File Offset: 0x0001F0F8 private static string EncodeAddresses(MailAddressCollection addresses) { StringBuilder stringBuilder = new StringBuilder(); bool flag = true; foreach (MailAddress mailAddress in addresses) { if (!flag) { stringBuilder.Append(", "); } stringBuilder.Append(SmtpClient.EncodeAddress(mailAddress)); flag = false; } return stringBuilder.ToString(); } // Token: 0x06000B21 RID: 2849 RVA: 0x00020F80 File Offset: 0x0001F180 private string EncodeSubjectRFC2047(MailMessage message) { return global::System.Net.Mime.ContentType.EncodeSubjectRFC2047(message.Subject, message.SubjectEncoding); } // Token: 0x06000B22 RID: 2850 RVA: 0x00020F94 File Offset: 0x0001F194 private string EncodeBody(MailMessage message) { string body = message.Body; Encoding bodyEncoding = message.BodyEncoding; global::System.Net.Mime.TransferEncoding contentTransferEncoding = message.ContentTransferEncoding; if (contentTransferEncoding == global::System.Net.Mime.TransferEncoding.Base64) { return Convert.ToBase64String(bodyEncoding.GetBytes(body), Base64FormattingOptions.InsertLineBreaks); } if (contentTransferEncoding != global::System.Net.Mime.TransferEncoding.SevenBit) { return this.ToQuotedPrintable(body, bodyEncoding); } return body; } // Token: 0x06000B23 RID: 2851 RVA: 0x00020FE4 File Offset: 0x0001F1E4 private string EncodeBody(AlternateView av) { byte[] array = new byte[av.ContentStream.Length]; av.ContentStream.Read(array, 0, array.Length); global::System.Net.Mime.TransferEncoding transferEncoding = av.TransferEncoding; if (transferEncoding == global::System.Net.Mime.TransferEncoding.Base64) { return Convert.ToBase64String(array, Base64FormattingOptions.InsertLineBreaks); } if (transferEncoding != global::System.Net.Mime.TransferEncoding.SevenBit) { return this.ToQuotedPrintable(array); } return Encoding.ASCII.GetString(array); } // Token: 0x06000B24 RID: 2852 RVA: 0x0002104C File Offset: 0x0001F24C private void EndSection(string section) { this.SendData(string.Format("--{0}--", section)); this.SendData(string.Empty); } // Token: 0x06000B25 RID: 2853 RVA: 0x0002106C File Offset: 0x0001F26C private string GenerateBoundary() { string text = SmtpClient.GenerateBoundary(this.boundaryIndex); this.boundaryIndex++; return text; } // Token: 0x06000B26 RID: 2854 RVA: 0x00021094 File Offset: 0x0001F294 private static string GenerateBoundary(int index) { return string.Format("--boundary_{0}_{1}", index, Guid.NewGuid().ToString("D")); } // Token: 0x06000B27 RID: 2855 RVA: 0x000210C4 File Offset: 0x0001F2C4 private bool IsError(SmtpClient.SmtpResponse status) { return status.StatusCode >= (SmtpStatusCode)400; } /// Raises the event. /// An that contains event data. // Token: 0x06000B28 RID: 2856 RVA: 0x000210D8 File Offset: 0x0001F2D8 protected void OnSendCompleted(global::System.ComponentModel.AsyncCompletedEventArgs e) { try { if (this.SendCompleted != null) { this.SendCompleted(this, e); } } finally { this.worker = null; this.user_async_state = null; } } // Token: 0x06000B29 RID: 2857 RVA: 0x00021130 File Offset: 0x0001F330 private void CheckCancellation() { if (this.worker != null && this.worker.CancellationPending) { throw new SmtpClient.CancellationException(); } } // Token: 0x06000B2A RID: 2858 RVA: 0x00021154 File Offset: 0x0001F354 private SmtpClient.SmtpResponse Read() { byte[] array = new byte[512]; int num = 0; bool flag = false; do { this.CheckCancellation(); int num2 = this.stream.Read(array, num, array.Length - num); if (num2 <= 0) { break; } int num3 = num + num2 - 1; if (num3 > 4 && (array[num3] == 10 || array[num3] == 13)) { int num4 = num3 - 3; while (num4 >= 0 && array[num4] != 10 && array[num4] != 13) { num4--; } flag = array[num4 + 4] == 32; } num += num2; if (num == array.Length) { byte[] array2 = new byte[array.Length * 2]; Array.Copy(array, 0, array2, 0, array.Length); array = array2; } } while (!flag); if (num > 0) { Encoding encoding = new ASCIIEncoding(); string @string = encoding.GetString(array, 0, num - 1); return SmtpClient.SmtpResponse.Parse(@string); } throw new IOException("Connection closed"); } // Token: 0x06000B2B RID: 2859 RVA: 0x00021264 File Offset: 0x0001F464 private void ResetExtensions() { this.authMechs = SmtpClient.AuthMechs.None; } // Token: 0x06000B2C RID: 2860 RVA: 0x00021270 File Offset: 0x0001F470 private void ParseExtensions(string extens) { char[] array = new char[] { ' ' }; string[] array2 = extens.Split(new char[] { '\n' }); foreach (string text in array2) { if (text.Length >= 4) { string text2 = text.Substring(4); if (text2.StartsWith("AUTH ", StringComparison.Ordinal)) { string[] array4 = text2.Split(array); for (int j = 1; j < array4.Length; j++) { string text3 = array4[j].Trim(); string text4 = text3; switch (text4) { case "CRAM-MD5": this.authMechs |= SmtpClient.AuthMechs.CramMD5; break; case "DIGEST-MD5": this.authMechs |= SmtpClient.AuthMechs.DigestMD5; break; case "GSSAPI": this.authMechs |= SmtpClient.AuthMechs.GssAPI; break; case "KERBEROS_V4": this.authMechs |= SmtpClient.AuthMechs.Kerberos4; break; case "LOGIN": this.authMechs |= SmtpClient.AuthMechs.Login; break; case "PLAIN": this.authMechs |= SmtpClient.AuthMechs.Plain; break; } } } } } } /// Sends the specified message to an SMTP server for delivery. /// A that contains the message to send. /// /// is null.-or- is null.-or- is null. /// There are no recipients in , , and . /// This has a call in progress.-or- is null.-or- is equal to the empty string ("").-or- is zero. /// This object has been disposed. /// The connection to the SMTP server failed.-or-Authentication failed.-or-The operation timed out. /// The message could not be delivered to one or more of the recipients in , , or . // Token: 0x06000B2D RID: 2861 RVA: 0x00021434 File Offset: 0x0001F634 public void Send(MailMessage message) { if (message == null) { throw new ArgumentNullException("message"); } if (this.deliveryMethod == SmtpDeliveryMethod.Network && (this.Host == null || this.Host.Trim().Length == 0)) { throw new InvalidOperationException("The SMTP host was not specified"); } if (this.deliveryMethod == SmtpDeliveryMethod.PickupDirectoryFromIis) { throw new NotSupportedException("IIS delivery is not supported"); } if (this.port == 0) { this.port = 25; } this.mutex.WaitOne(); try { this.messageInProcess = message; if (this.deliveryMethod == SmtpDeliveryMethod.SpecifiedPickupDirectory) { this.SendToFile(message); } else { this.SendInternal(message); } } catch (SmtpClient.CancellationException) { } catch (SmtpException) { throw; } catch (Exception ex) { throw new SmtpException("Message could not be sent.", ex); } finally { this.mutex.ReleaseMutex(); this.messageInProcess = null; } } // Token: 0x06000B2E RID: 2862 RVA: 0x00021580 File Offset: 0x0001F780 private void SendInternal(MailMessage message) { this.CheckCancellation(); try { this.client = new global::System.Net.Sockets.TcpClient(this.host, this.port); this.stream = this.client.GetStream(); this.writer = new StreamWriter(this.stream); this.reader = new StreamReader(this.stream); this.SendCore(message); } finally { if (this.writer != null) { this.writer.Close(); } if (this.reader != null) { this.reader.Close(); } if (this.stream != null) { this.stream.Close(); } if (this.client != null) { this.client.Close(); } } } // Token: 0x06000B2F RID: 2863 RVA: 0x00021660 File Offset: 0x0001F860 private void SendToFile(MailMessage message) { if (!Path.IsPathRooted(this.pickupDirectoryLocation)) { throw new SmtpException("Only absolute directories are allowed for pickup directory."); } string text = Path.Combine(this.pickupDirectoryLocation, Guid.NewGuid() + ".eml"); try { this.writer = new StreamWriter(text); MailAddress from = message.From; if (from == null) { from = this.defaultFrom; } this.SendHeader("Date", DateTime.Now.ToString("ddd, dd MMM yyyy HH':'mm':'ss zzz", DateTimeFormatInfo.InvariantInfo)); this.SendHeader("From", from.ToString()); this.SendHeader("To", message.To.ToString()); if (message.CC.Count > 0) { this.SendHeader("Cc", message.CC.ToString()); } this.SendHeader("Subject", this.EncodeSubjectRFC2047(message)); foreach (string text2 in message.Headers.AllKeys) { this.SendHeader(text2, message.Headers[text2]); } this.AddPriorityHeader(message); this.boundaryIndex = 0; if (message.Attachments.Count > 0) { this.SendWithAttachments(message); } else { this.SendWithoutAttachments(message, null, false); } } finally { if (this.writer != null) { this.writer.Close(); } this.writer = null; } } // Token: 0x06000B30 RID: 2864 RVA: 0x000217FC File Offset: 0x0001F9FC private void SendCore(MailMessage message) { SmtpClient.SmtpResponse smtpResponse = this.Read(); if (this.IsError(smtpResponse)) { throw new SmtpException(smtpResponse.StatusCode, smtpResponse.Description); } smtpResponse = this.SendCommand("EHLO " + Dns.GetHostName()); if (this.IsError(smtpResponse)) { smtpResponse = this.SendCommand("HELO " + Dns.GetHostName()); if (this.IsError(smtpResponse)) { throw new SmtpException(smtpResponse.StatusCode, smtpResponse.Description); } } else { string description = smtpResponse.Description; if (description != null) { this.ParseExtensions(description); } } if (this.enableSsl) { this.InitiateSecureConnection(); this.ResetExtensions(); this.writer = new StreamWriter(this.stream); this.reader = new StreamReader(this.stream); smtpResponse = this.SendCommand("EHLO " + Dns.GetHostName()); if (this.IsError(smtpResponse)) { smtpResponse = this.SendCommand("HELO " + Dns.GetHostName()); if (this.IsError(smtpResponse)) { throw new SmtpException(smtpResponse.StatusCode, smtpResponse.Description); } } else { string description2 = smtpResponse.Description; if (description2 != null) { this.ParseExtensions(description2); } } } if (this.authMechs != SmtpClient.AuthMechs.None) { this.Authenticate(); } MailAddress from = message.From; if (from == null) { from = this.defaultFrom; } smtpResponse = this.SendCommand("MAIL FROM:<" + from.Address + '>'); if (this.IsError(smtpResponse)) { throw new SmtpException(smtpResponse.StatusCode, smtpResponse.Description); } List list = new List(); for (int i = 0; i < message.To.Count; i++) { smtpResponse = this.SendCommand("RCPT TO:<" + message.To[i].Address + '>'); if (this.IsError(smtpResponse)) { list.Add(new SmtpFailedRecipientException(smtpResponse.StatusCode, message.To[i].Address)); } } for (int j = 0; j < message.CC.Count; j++) { smtpResponse = this.SendCommand("RCPT TO:<" + message.CC[j].Address + '>'); if (this.IsError(smtpResponse)) { list.Add(new SmtpFailedRecipientException(smtpResponse.StatusCode, message.CC[j].Address)); } } for (int k = 0; k < message.Bcc.Count; k++) { smtpResponse = this.SendCommand("RCPT TO:<" + message.Bcc[k].Address + '>'); if (this.IsError(smtpResponse)) { list.Add(new SmtpFailedRecipientException(smtpResponse.StatusCode, message.Bcc[k].Address)); } } if (list.Count > 0) { throw new SmtpFailedRecipientsException("failed recipients", list.ToArray()); } smtpResponse = this.SendCommand("DATA"); if (this.IsError(smtpResponse)) { throw new SmtpException(smtpResponse.StatusCode, smtpResponse.Description); } string text = DateTime.Now.ToString("ddd, dd MMM yyyy HH':'mm':'ss zzz", DateTimeFormatInfo.InvariantInfo); text = text.Remove(text.Length - 3, 1); this.SendHeader("Date", text); this.SendHeader("From", SmtpClient.EncodeAddress(from)); this.SendHeader("To", SmtpClient.EncodeAddresses(message.To)); if (message.CC.Count > 0) { this.SendHeader("Cc", SmtpClient.EncodeAddresses(message.CC)); } this.SendHeader("Subject", this.EncodeSubjectRFC2047(message)); string text2 = "normal"; switch (message.Priority) { case MailPriority.Normal: text2 = "normal"; break; case MailPriority.Low: text2 = "non-urgent"; break; case MailPriority.High: text2 = "urgent"; break; } this.SendHeader("Priority", text2); if (message.Sender != null) { this.SendHeader("Sender", SmtpClient.EncodeAddress(message.Sender)); } if (message.ReplyToList.Count > 0) { this.SendHeader("Reply-To", SmtpClient.EncodeAddresses(message.ReplyToList)); } foreach (string text3 in message.Headers.AllKeys) { this.SendHeader(text3, message.Headers[text3]); } this.AddPriorityHeader(message); this.boundaryIndex = 0; if (message.Attachments.Count > 0) { this.SendWithAttachments(message); } else { this.SendWithoutAttachments(message, null, false); } this.SendDot(); smtpResponse = this.Read(); if (this.IsError(smtpResponse)) { throw new SmtpException(smtpResponse.StatusCode, smtpResponse.Description); } try { smtpResponse = this.SendCommand("QUIT"); } catch (IOException) { } } /// Sends the specified e-mail message to an SMTP server for delivery. The message sender, recipients, subject, and message body are specified using objects. /// A that contains the address information of the message sender. /// A that contains the addresses that the message is sent to. /// A that contains the subject line for the message. /// A that contains the message body. /// /// is null.-or- is null. /// /// is .-or- is . /// This has a call in progress.-or- is null.-or- is equal to the empty string ("").-or- is zero. /// This object has been disposed. /// The connection to the SMTP server failed.-or-Authentication failed.-or-The operation timed out. /// The message could not be delivered to one or more of the recipients in . // Token: 0x06000B31 RID: 2865 RVA: 0x00021D84 File Offset: 0x0001FF84 public void Send(string from, string to, string subject, string body) { this.Send(new MailMessage(from, to, subject, body)); } // Token: 0x06000B32 RID: 2866 RVA: 0x00021D98 File Offset: 0x0001FF98 private void SendDot() { this.writer.Write(".\r\n"); this.writer.Flush(); } // Token: 0x06000B33 RID: 2867 RVA: 0x00021DB8 File Offset: 0x0001FFB8 private void SendData(string data) { if (string.IsNullOrEmpty(data)) { this.writer.Write("\r\n"); this.writer.Flush(); return; } StringReader stringReader = new StringReader(data); bool flag = this.deliveryMethod == SmtpDeliveryMethod.Network; string text; while ((text = stringReader.ReadLine()) != null) { this.CheckCancellation(); if (flag) { int i; for (i = 0; i < text.Length; i++) { if (text[i] != '.') { break; } } if (i > 0 && i == text.Length) { text += "."; } } this.writer.Write(text); this.writer.Write("\r\n"); } this.writer.Flush(); } /// Sends the specified e-mail message to an SMTP server for delivery. This method does not block the calling thread and allows the caller to pass an object to the method that is invoked when the operation completes. /// A that contains the message to send. /// A user-defined object that is passed to the method invoked when the asynchronous operation completes. /// /// is null.-or- is null.-or- is null. /// There are no recipients in , , and . /// This has a call in progress.-or- is null.-or- is equal to the empty string ("").-or- is zero. /// This object has been disposed. /// The connection to the SMTP server failed.-or-Authentication failed.-or-The operation timed out. /// The could not be delivered to one or more of the recipients in , , or . // Token: 0x06000B34 RID: 2868 RVA: 0x00021E8C File Offset: 0x0002008C public void SendAsync(MailMessage message, object userToken) { if (this.worker != null) { throw new InvalidOperationException("Another SendAsync operation is in progress"); } this.worker = new global::System.ComponentModel.BackgroundWorker(); this.worker.DoWork += delegate(object o, global::System.ComponentModel.DoWorkEventArgs ea) { try { this.user_async_state = ea.Argument; this.Send(message); } catch (Exception ex) { ea.Result = ex; throw ex; } }; this.worker.WorkerSupportsCancellation = true; this.worker.RunWorkerCompleted += delegate(object o, global::System.ComponentModel.RunWorkerCompletedEventArgs ea) { this.OnSendCompleted(new global::System.ComponentModel.AsyncCompletedEventArgs(ea.Error, ea.Cancelled, this.user_async_state)); }; this.worker.RunWorkerAsync(userToken); } /// Sends an e-mail message to an SMTP server for delivery. The message sender, recipients, subject, and message body are specified using objects. This method does not block the calling thread and allows the caller to pass an object to the method that is invoked when the operation completes. /// A that contains the address information of the message sender. /// A that contains the address that the message is sent to. /// A that contains the subject line for the message. /// A that contains the message body. /// A user-defined object that is passed to the method invoked when the asynchronous operation completes. /// /// is null.-or- is null. /// /// is .-or- is . /// This has a call in progress.-or- is null.-or- is equal to the empty string ("").-or- is zero. /// This object has been disposed. /// The connection to the SMTP server failed.-or-Authentication failed.-or-The operation timed out. /// The message could not be delivered to one or more of the recipients in . // Token: 0x06000B35 RID: 2869 RVA: 0x00021F14 File Offset: 0x00020114 public void SendAsync(string from, string to, string subject, string body, object userToken) { this.SendAsync(new MailMessage(from, to, subject, body), userToken); } /// Cancels an asynchronous operation to send an e-mail message. /// This object has been disposed. // Token: 0x06000B36 RID: 2870 RVA: 0x00021F28 File Offset: 0x00020128 public void SendAsyncCancel() { if (this.worker == null) { throw new InvalidOperationException("SendAsync operation is not in progress"); } this.worker.CancelAsync(); } // Token: 0x06000B37 RID: 2871 RVA: 0x00021F4C File Offset: 0x0002014C private void AddPriorityHeader(MailMessage message) { MailPriority priority = message.Priority; if (priority != MailPriority.Low) { if (priority == MailPriority.High) { this.SendHeader("Priority", "Urgent"); this.SendHeader("Importance", "high"); this.SendHeader("X-Priority", "1"); } } else { this.SendHeader("Priority", "Non-Urgent"); this.SendHeader("Importance", "low"); this.SendHeader("X-Priority", "5"); } } // Token: 0x06000B38 RID: 2872 RVA: 0x00021FE0 File Offset: 0x000201E0 private void SendSimpleBody(MailMessage message) { this.SendHeader("Content-Type", message.BodyContentType.ToString()); if (message.ContentTransferEncoding != global::System.Net.Mime.TransferEncoding.SevenBit) { this.SendHeader("Content-Transfer-Encoding", SmtpClient.GetTransferEncodingName(message.ContentTransferEncoding)); } this.SendData(string.Empty); this.SendData(this.EncodeBody(message)); } // Token: 0x06000B39 RID: 2873 RVA: 0x00022040 File Offset: 0x00020240 private void SendBodylessSingleAlternate(AlternateView av) { this.SendHeader("Content-Type", av.ContentType.ToString()); if (av.TransferEncoding != global::System.Net.Mime.TransferEncoding.SevenBit) { this.SendHeader("Content-Transfer-Encoding", SmtpClient.GetTransferEncodingName(av.TransferEncoding)); } this.SendData(string.Empty); this.SendData(this.EncodeBody(av)); } // Token: 0x06000B3A RID: 2874 RVA: 0x000220A0 File Offset: 0x000202A0 private void SendWithoutAttachments(MailMessage message, string boundary, bool attachmentExists) { if (message.Body == null && message.AlternateViews.Count == 1) { this.SendBodylessSingleAlternate(message.AlternateViews[0]); } else if (message.AlternateViews.Count > 0) { this.SendBodyWithAlternateViews(message, boundary, attachmentExists); } else { this.SendSimpleBody(message); } } // Token: 0x06000B3B RID: 2875 RVA: 0x00022108 File Offset: 0x00020308 private void SendWithAttachments(MailMessage message) { string text = this.GenerateBoundary(); this.SendHeader("Content-Type", new global::System.Net.Mime.ContentType { Boundary = text, MediaType = "multipart/mixed", CharSet = null }.ToString()); this.SendData(string.Empty); Attachment attachment = null; if (message.AlternateViews.Count > 0) { this.SendWithoutAttachments(message, text, true); } else { attachment = Attachment.CreateAttachmentFromString(message.Body, null, message.BodyEncoding, (!message.IsBodyHtml) ? "text/plain" : "text/html"); message.Attachments.Insert(0, attachment); } try { this.SendAttachments(message, attachment, text); } finally { if (attachment != null) { message.Attachments.Remove(attachment); } } this.EndSection(text); } // Token: 0x06000B3C RID: 2876 RVA: 0x000221F8 File Offset: 0x000203F8 private void SendBodyWithAlternateViews(MailMessage message, string boundary, bool attachmentExists) { AlternateViewCollection alternateViews = message.AlternateViews; string text = this.GenerateBoundary(); global::System.Net.Mime.ContentType contentType = new global::System.Net.Mime.ContentType(); contentType.Boundary = text; contentType.MediaType = "multipart/alternative"; if (!attachmentExists) { this.SendHeader("Content-Type", contentType.ToString()); this.SendData(string.Empty); } AlternateView alternateView = null; if (message.Body != null) { alternateView = AlternateView.CreateAlternateViewFromString(message.Body, message.BodyEncoding, (!message.IsBodyHtml) ? "text/plain" : "text/html"); alternateViews.Insert(0, alternateView); this.StartSection(boundary, contentType); } try { foreach (AlternateView alternateView2 in alternateViews) { string text2 = null; if (alternateView2.LinkedResources.Count > 0) { text2 = this.GenerateBoundary(); global::System.Net.Mime.ContentType contentType2 = new global::System.Net.Mime.ContentType("multipart/related"); contentType2.Boundary = text2; contentType2.Parameters["type"] = alternateView2.ContentType.ToString(); this.StartSection(text, contentType2); this.StartSection(text2, alternateView2.ContentType, alternateView2.TransferEncoding); } else { global::System.Net.Mime.ContentType contentType2 = new global::System.Net.Mime.ContentType(alternateView2.ContentType.ToString()); this.StartSection(text, contentType2, alternateView2.TransferEncoding); } global::System.Net.Mime.TransferEncoding transferEncoding = alternateView2.TransferEncoding; switch (transferEncoding + 1) { case global::System.Net.Mime.TransferEncoding.QuotedPrintable: case (global::System.Net.Mime.TransferEncoding)3: { byte[] array = new byte[alternateView2.ContentStream.Length]; alternateView2.ContentStream.Read(array, 0, array.Length); this.SendData(Encoding.ASCII.GetString(array)); break; } case global::System.Net.Mime.TransferEncoding.Base64: { byte[] array2 = new byte[alternateView2.ContentStream.Length]; alternateView2.ContentStream.Read(array2, 0, array2.Length); this.SendData(this.ToQuotedPrintable(array2)); break; } case global::System.Net.Mime.TransferEncoding.SevenBit: { byte[] array = new byte[alternateView2.ContentStream.Length]; alternateView2.ContentStream.Read(array, 0, array.Length); this.SendData(Convert.ToBase64String(array, Base64FormattingOptions.InsertLineBreaks)); break; } } if (alternateView2.LinkedResources.Count > 0) { this.SendLinkedResources(message, alternateView2.LinkedResources, text2); this.EndSection(text2); } if (!attachmentExists) { this.SendData(string.Empty); } } } finally { if (alternateView != null) { alternateViews.Remove(alternateView); } } this.EndSection(text); } // Token: 0x06000B3D RID: 2877 RVA: 0x000224C8 File Offset: 0x000206C8 private void SendLinkedResources(MailMessage message, LinkedResourceCollection resources, string boundary) { foreach (LinkedResource linkedResource in resources) { this.StartSection(boundary, linkedResource.ContentType, linkedResource.TransferEncoding, linkedResource); global::System.Net.Mime.TransferEncoding transferEncoding = linkedResource.TransferEncoding; switch (transferEncoding + 1) { case global::System.Net.Mime.TransferEncoding.QuotedPrintable: case (global::System.Net.Mime.TransferEncoding)3: { byte[] array = new byte[linkedResource.ContentStream.Length]; linkedResource.ContentStream.Read(array, 0, array.Length); this.SendData(Encoding.ASCII.GetString(array)); break; } case global::System.Net.Mime.TransferEncoding.Base64: { byte[] array2 = new byte[linkedResource.ContentStream.Length]; linkedResource.ContentStream.Read(array2, 0, array2.Length); this.SendData(this.ToQuotedPrintable(array2)); break; } case global::System.Net.Mime.TransferEncoding.SevenBit: { byte[] array = new byte[linkedResource.ContentStream.Length]; linkedResource.ContentStream.Read(array, 0, array.Length); this.SendData(Convert.ToBase64String(array, Base64FormattingOptions.InsertLineBreaks)); break; } } } } // Token: 0x06000B3E RID: 2878 RVA: 0x000225FC File Offset: 0x000207FC private void SendAttachments(MailMessage message, Attachment body, string boundary) { foreach (Attachment attachment in message.Attachments) { global::System.Net.Mime.ContentType contentType = new global::System.Net.Mime.ContentType(attachment.ContentType.ToString()); if (attachment.Name != null) { contentType.Name = attachment.Name; if (attachment.NameEncoding != null) { contentType.CharSet = attachment.NameEncoding.HeaderName; } attachment.ContentDisposition.FileName = attachment.Name; } this.StartSection(boundary, contentType, attachment.TransferEncoding, (attachment != body) ? attachment.ContentDisposition : null); byte[] array = new byte[attachment.ContentStream.Length]; attachment.ContentStream.Read(array, 0, array.Length); global::System.Net.Mime.TransferEncoding transferEncoding = attachment.TransferEncoding; switch (transferEncoding + 1) { case global::System.Net.Mime.TransferEncoding.QuotedPrintable: case (global::System.Net.Mime.TransferEncoding)3: this.SendData(Encoding.ASCII.GetString(array)); break; case global::System.Net.Mime.TransferEncoding.Base64: this.SendData(this.ToQuotedPrintable(array)); break; case global::System.Net.Mime.TransferEncoding.SevenBit: this.SendData(Convert.ToBase64String(array, Base64FormattingOptions.InsertLineBreaks)); break; } this.SendData(string.Empty); } } // Token: 0x06000B3F RID: 2879 RVA: 0x0002275C File Offset: 0x0002095C private SmtpClient.SmtpResponse SendCommand(string command) { this.writer.Write(command); this.writer.Write("\r\n"); this.writer.Flush(); return this.Read(); } // Token: 0x06000B40 RID: 2880 RVA: 0x00022798 File Offset: 0x00020998 private void SendHeader(string name, string value) { this.SendData(string.Format("{0}: {1}", name, value)); } // Token: 0x06000B41 RID: 2881 RVA: 0x000227AC File Offset: 0x000209AC private void StartSection(string section, global::System.Net.Mime.ContentType sectionContentType) { this.SendData(string.Format("--{0}", section)); this.SendHeader("content-type", sectionContentType.ToString()); this.SendData(string.Empty); } // Token: 0x06000B42 RID: 2882 RVA: 0x000227E8 File Offset: 0x000209E8 private void StartSection(string section, global::System.Net.Mime.ContentType sectionContentType, global::System.Net.Mime.TransferEncoding transferEncoding) { this.SendData(string.Format("--{0}", section)); this.SendHeader("content-type", sectionContentType.ToString()); this.SendHeader("content-transfer-encoding", SmtpClient.GetTransferEncodingName(transferEncoding)); this.SendData(string.Empty); } // Token: 0x06000B43 RID: 2883 RVA: 0x00022834 File Offset: 0x00020A34 private void StartSection(string section, global::System.Net.Mime.ContentType sectionContentType, global::System.Net.Mime.TransferEncoding transferEncoding, LinkedResource lr) { this.SendData(string.Format("--{0}", section)); this.SendHeader("content-type", sectionContentType.ToString()); this.SendHeader("content-transfer-encoding", SmtpClient.GetTransferEncodingName(transferEncoding)); if (lr.ContentId != null && lr.ContentId.Length > 0) { this.SendHeader("content-ID", "<" + lr.ContentId + ">"); } this.SendData(string.Empty); } // Token: 0x06000B44 RID: 2884 RVA: 0x000228C0 File Offset: 0x00020AC0 private void StartSection(string section, global::System.Net.Mime.ContentType sectionContentType, global::System.Net.Mime.TransferEncoding transferEncoding, global::System.Net.Mime.ContentDisposition contentDisposition) { this.SendData(string.Format("--{0}", section)); this.SendHeader("content-type", sectionContentType.ToString()); this.SendHeader("content-transfer-encoding", SmtpClient.GetTransferEncodingName(transferEncoding)); if (contentDisposition != null) { this.SendHeader("content-disposition", contentDisposition.ToString()); } this.SendData(string.Empty); } // Token: 0x06000B45 RID: 2885 RVA: 0x00022924 File Offset: 0x00020B24 private string ToQuotedPrintable(string input, Encoding enc) { byte[] bytes = enc.GetBytes(input); return this.ToQuotedPrintable(bytes); } // Token: 0x06000B46 RID: 2886 RVA: 0x00022940 File Offset: 0x00020B40 private string ToQuotedPrintable(byte[] bytes) { StringWriter stringWriter = new StringWriter(); int num = 0; StringBuilder stringBuilder = new StringBuilder("=", 3); byte b = 61; char c = '\0'; int i = 0; while (i < bytes.Length) { byte b2 = bytes[i]; int num2; if (b2 > 127 || b2 == b) { stringBuilder.Length = 1; stringBuilder.Append(Convert.ToString(b2, 16).ToUpperInvariant()); num2 = 3; goto IL_8E; } c = Convert.ToChar(b2); if (c != '\r' && c != '\n') { num2 = 1; goto IL_8E; } stringWriter.Write(c); num = 0; IL_C7: i++; continue; IL_8E: num += num2; if (num > 75) { stringWriter.Write("=\r\n"); num = num2; } if (num2 == 1) { stringWriter.Write(c); goto IL_C7; } stringWriter.Write(stringBuilder.ToString()); goto IL_C7; } return stringWriter.ToString(); } // Token: 0x06000B47 RID: 2887 RVA: 0x00022A2C File Offset: 0x00020C2C private static string GetTransferEncodingName(global::System.Net.Mime.TransferEncoding encoding) { switch (encoding) { case global::System.Net.Mime.TransferEncoding.QuotedPrintable: return "quoted-printable"; case global::System.Net.Mime.TransferEncoding.Base64: return "base64"; case global::System.Net.Mime.TransferEncoding.SevenBit: return "7bit"; default: return "unknown"; } } // Token: 0x06000B48 RID: 2888 RVA: 0x00022A6C File Offset: 0x00020C6C private void InitiateSecureConnection() { SmtpClient.SmtpResponse smtpResponse = this.SendCommand("STARTTLS"); if (this.IsError(smtpResponse)) { throw new SmtpException(SmtpStatusCode.GeneralFailure, "Server does not support secure connections."); } global::System.Net.Security.SslStream sslStream = new global::System.Net.Security.SslStream(this.stream, false, this.callback, null); this.CheckCancellation(); sslStream.AuthenticateAsClient(this.Host, this.ClientCertificates, global::System.Security.Authentication.SslProtocols.Default, false); this.stream = sslStream; } // Token: 0x06000B49 RID: 2889 RVA: 0x00022AD8 File Offset: 0x00020CD8 private void Authenticate() { string text; string text2; if (this.UseDefaultCredentials) { text = CredentialCache.DefaultCredentials.GetCredential(new global::System.Uri("smtp://" + this.host), "basic").UserName; text2 = CredentialCache.DefaultCredentials.GetCredential(new global::System.Uri("smtp://" + this.host), "basic").Password; } else { if (this.Credentials == null) { return; } text = this.Credentials.GetCredential(this.host, this.port, "smtp").UserName; text2 = this.Credentials.GetCredential(this.host, this.port, "smtp").Password; } this.Authenticate(text, text2); } // Token: 0x06000B4A RID: 2890 RVA: 0x00022BAC File Offset: 0x00020DAC private void Authenticate(string Username, string Password) { SmtpClient.SmtpResponse smtpResponse = this.SendCommand("AUTH LOGIN"); if (smtpResponse.StatusCode != (SmtpStatusCode)334) { throw new SmtpException(smtpResponse.StatusCode, smtpResponse.Description); } smtpResponse = this.SendCommand(Convert.ToBase64String(Encoding.ASCII.GetBytes(Username))); if (smtpResponse.StatusCode != (SmtpStatusCode)334) { throw new SmtpException(smtpResponse.StatusCode, smtpResponse.Description); } smtpResponse = this.SendCommand(Convert.ToBase64String(Encoding.ASCII.GetBytes(Password))); if (this.IsError(smtpResponse)) { throw new SmtpException(smtpResponse.StatusCode, smtpResponse.Description); } } // Token: 0x04000B22 RID: 2850 private string host; // Token: 0x04000B23 RID: 2851 private int port; // Token: 0x04000B24 RID: 2852 private int timeout = 100000; // Token: 0x04000B25 RID: 2853 private ICredentialsByHost credentials; // Token: 0x04000B26 RID: 2854 private string pickupDirectoryLocation; // Token: 0x04000B27 RID: 2855 private SmtpDeliveryMethod deliveryMethod; // Token: 0x04000B28 RID: 2856 private bool enableSsl; // Token: 0x04000B29 RID: 2857 private global::System.Security.Cryptography.X509Certificates.X509CertificateCollection clientCertificates; // Token: 0x04000B2A RID: 2858 private global::System.Net.Sockets.TcpClient client; // Token: 0x04000B2B RID: 2859 private Stream stream; // Token: 0x04000B2C RID: 2860 private StreamWriter writer; // Token: 0x04000B2D RID: 2861 private StreamReader reader; // Token: 0x04000B2E RID: 2862 private int boundaryIndex; // Token: 0x04000B2F RID: 2863 private MailAddress defaultFrom; // Token: 0x04000B30 RID: 2864 private MailMessage messageInProcess; // Token: 0x04000B31 RID: 2865 private global::System.ComponentModel.BackgroundWorker worker; // Token: 0x04000B32 RID: 2866 private object user_async_state; // Token: 0x04000B33 RID: 2867 private SmtpClient.AuthMechs authMechs; // Token: 0x04000B34 RID: 2868 private Mutex mutex = new Mutex(); // Token: 0x04000B35 RID: 2869 private global::System.Net.Security.RemoteCertificateValidationCallback callback = delegate(object sender, X509Certificate certificate, global::System.Security.Cryptography.X509Certificates.X509Chain chain, global::System.Net.Security.SslPolicyErrors sslPolicyErrors) { if (ServicePointManager.ServerCertificateValidationCallback != null) { return ServicePointManager.ServerCertificateValidationCallback(sender, certificate, chain, sslPolicyErrors); } if (sslPolicyErrors != global::System.Net.Security.SslPolicyErrors.None) { throw new InvalidOperationException("SSL authentication error: " + sslPolicyErrors); } return true; }; // Token: 0x02000144 RID: 324 [Flags] private enum AuthMechs { // Token: 0x04000B3B RID: 2875 None = 0, // Token: 0x04000B3C RID: 2876 CramMD5 = 1, // Token: 0x04000B3D RID: 2877 DigestMD5 = 2, // Token: 0x04000B3E RID: 2878 GssAPI = 4, // Token: 0x04000B3F RID: 2879 Kerberos4 = 8, // Token: 0x04000B40 RID: 2880 Login = 16, // Token: 0x04000B41 RID: 2881 Plain = 32 } // Token: 0x02000145 RID: 325 private class CancellationException : Exception { } // Token: 0x02000146 RID: 326 private struct HeaderName { // Token: 0x04000B42 RID: 2882 public const string ContentTransferEncoding = "Content-Transfer-Encoding"; // Token: 0x04000B43 RID: 2883 public const string ContentType = "Content-Type"; // Token: 0x04000B44 RID: 2884 public const string Bcc = "Bcc"; // Token: 0x04000B45 RID: 2885 public const string Cc = "Cc"; // Token: 0x04000B46 RID: 2886 public const string From = "From"; // Token: 0x04000B47 RID: 2887 public const string Subject = "Subject"; // Token: 0x04000B48 RID: 2888 public const string To = "To"; // Token: 0x04000B49 RID: 2889 public const string MimeVersion = "MIME-Version"; // Token: 0x04000B4A RID: 2890 public const string MessageId = "Message-ID"; // Token: 0x04000B4B RID: 2891 public const string Priority = "Priority"; // Token: 0x04000B4C RID: 2892 public const string Importance = "Importance"; // Token: 0x04000B4D RID: 2893 public const string XPriority = "X-Priority"; // Token: 0x04000B4E RID: 2894 public const string Date = "Date"; } // Token: 0x02000147 RID: 327 private struct SmtpResponse { // Token: 0x06000B4D RID: 2893 RVA: 0x00022CAC File Offset: 0x00020EAC public static SmtpClient.SmtpResponse Parse(string line) { SmtpClient.SmtpResponse smtpResponse = default(SmtpClient.SmtpResponse); if (line.Length < 4) { throw new SmtpException("Response is to short " + line.Length + "."); } if (line[3] != ' ' && line[3] != '-') { throw new SmtpException("Response format is wrong.(" + line + ")"); } smtpResponse.StatusCode = (SmtpStatusCode)int.Parse(line.Substring(0, 3)); smtpResponse.Description = line; return smtpResponse; } // Token: 0x04000B4F RID: 2895 public SmtpStatusCode StatusCode; // Token: 0x04000B50 RID: 2896 public string Description; } } }