Elmah.ErrorMailModule.SendMail C# (CSharp) Méthode

SendMail() protected méthode

Sends the e-mail using SmtpMail or SmtpClient.
protected SendMail ( MailMessage mail ) : void
mail System.Net.Mail.MailMessage
Résultat void
        protected virtual void SendMail(MailMessage mail)
        {
            if (mail == null)
                throw new ArgumentNullException("mail");

            //
            // Under .NET Framework 2.0, the authentication settings
            // go on the SmtpClient object rather than mail message
            // so these have to be set up here.
            //

            var client = new SmtpClient();

            var host = SmtpServer ?? string.Empty;

            if (host.Length > 0)
            {
                client.Host = host;
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
            }

            var port = SmtpPort;
            if (port > 0)
                client.Port = port;

            var userName = AuthUserName ?? string.Empty;
            var password = AuthPassword ?? string.Empty;

            if (userName.Length > 0 && password.Length > 0)
                client.Credentials = new NetworkCredential(userName, password);

            client.EnableSsl = UseSsl;

            client.Send(mail);
        }