Пример #1
0
        public async Task SendAsync(MailMessageDTO message)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            // Get MIME message
            var msg = message.ToMimeMessage();

            // Send message
            using (var mx = new SmtpClient())
            {
                await mx.ConnectAsync(this.HostName, this.Port, AllowSsl?SecureSocketOptions.Auto : SecureSocketOptions.None);

                if (AllowSsl)
                {
                    mx.ServerCertificateValidationCallback = this.ServerCertificateValidationCallback;
                }
                if (!string.IsNullOrEmpty(this.UserName) && !string.IsNullOrEmpty(this.Password))
                {
                    await mx.AuthenticateAsync(this.UserName, this.Password);
                }
                await mx.SendAsync(msg);

                await mx.DisconnectAsync(true);
            }
        }