System.Net.Mail.MailMessage.Dispose C# (CSharp) Method

Dispose() public method

public Dispose ( ) : void
return void
        public void Dispose()
        {
            Dispose(true);
        }

Same methods

MailMessage::Dispose ( bool disposing ) : void

Usage Example

Beispiel #1
0
        public bool SendMail(string fromAddress, string toAddress, string subject, string body)
        {
            var mail = new MailMessage(fromAddress, toAddress, subject, body);
            mail.IsBodyHtml = true;
            bool success = false;
            var mailSettings = Helpers.GetConfigSectionGroup<MailSettingsSectionGroup>("system.net/mailSettings");
            var pickupDir = mailSettings != null &&
                            mailSettings.Smtp != null &&
                            mailSettings.Smtp.SpecifiedPickupDirectory != null ?
                            mailSettings.Smtp.SpecifiedPickupDirectory.PickupDirectoryLocation : null;

            if (!string.IsNullOrWhiteSpace(pickupDir) && !Directory.Exists(pickupDir))
            {
                Directory.CreateDirectory(pickupDir);
            }

            try
            {
                this._smtpClient.Send(mail);
                success = true;
                mail.Dispose();
            }
            catch (Exception ex)
            {
                mail.Dispose();
                Logger.Log(string.Format("An error occurred while trying to send a mail with subject {0} to {1}.", mail.Subject, mail.To), ex, LogLevel.Error);

                throw;
            }

            return success;
        }
All Usage Examples Of System.Net.Mail.MailMessage::Dispose