protected virtual void Dispose(bool flag)
        {
            if (_disposed)
            {
                return;
            }

            _smtpClient?.Disconnect(true);
            _smtpClient?.Dispose();
            _disposed = true;

            if (flag)
            {
                GC.SuppressFinalize(this);
            }
        }
Exemple #2
0
        public async Task <bool> MailSendFromContactAsync(SendMailByIdRequest sendMailByIdRequest, Guid id)
        {
            var mail = await DbContext.emailAccountLists.SingleOrDefaultAsync(x => x.Id == id);

            var message = new MimeMessage();

            message.To.Add(new MailboxAddress(mail.Name, mail.Address));
            message.From.Add(new MailboxAddress(sendMailByIdRequest.NameFrom, mail.Address));
            message.Subject = sendMailByIdRequest.Subject;
            message.Body    = new TextPart(TextFormat.Html)
            {
                Text = sendMailByIdRequest.Content
            };
            using (var emailClient = new SmtpClient())
            {
                emailClient.Connect(_emailConfiguration.SmtpServer, _emailConfiguration.SmtpPort, true);
                emailClient.AuthenticationMechanisms.Remove("XOAUTH2");
                emailClient.Authenticate(_emailConfiguration.SmtpUsername, _emailConfiguration.SmtpPassword);
                emailClient.Send(message);
                emailClient.Disconnect(true);
            }
            return(true);
        }
Exemple #3
0
        //Use of API, MailKit by JStedfast
        public void OnNext(Contestant winner)
        {
            var message = new MimeMessage();

            message.From.Add(new MailboxAddress("Sweepstakes Runners", "marketingFirmEmail.com"));
            message.To.Add(new MailboxAddress(this.firstName + this.lastName, this.emailAddress));
            message.Subject = "The results of the Sweepstakes!!";
            if (this.status == "winner")
            {
                message = TailorMessageToWinner(message, winner);
            }
            else
            {
                message = TailorMessageToLoser(message, winner);
            }
            using (var client = new SmtpClient())
            {
                client.Connect("smtp.gmail.com", 587, false);
                client.Authenticate("marketingFirmEmail.com", "Password");
                client.Send(message);
                client.Disconnect(true);
            }
        }
        public async Task SendMailAsync(EmailMessage emailMessage)
        {
            var message = new MimeMessage();

            message.To.AddRange(emailMessage.ToAddresses.Select(x => new MailboxAddress(x.Name, x.Address)));
            message.From.AddRange(emailMessage.FromAddresses.Select(x => new MailboxAddress(x.Name, x.Address)));

            message.Subject = emailMessage.Subject;
            message.Body    = new TextPart(TextFormat.Html)
            {
                Text = emailMessage.Content
            };

            using (var emailClient = new SmtpClient())
            {
                emailClient.Connect(_emailConfiguration.SmtpServer, _emailConfiguration.SmtpPort);
                emailClient.AuthenticationMechanisms.Remove("XOAUTH2");
                emailClient.Authenticate(_emailConfiguration.SmtpUsername, _emailConfiguration.SmtpPassword);
                await emailClient.SendAsync(message);

                emailClient.Disconnect(true);
            }
        }
Exemple #5
0
        public Task SendEmailAsync(string email, string subject, string message)
        {
            var msg = new MimeMessage();

            msg.From.Add(new MailboxAddress("ESW05-G03 GROUP", "*****@*****.**"));
            msg.To.Add(new MailboxAddress("User", email));
            msg.Subject = subject + "ESW05-G03 GROUP NOTIFICATIONS";
            msg.Body    = new TextPart("html")
            {
                //Text = "Please < a href =\"https://albergueanimais.azurewebsites.net > login</a>"
                Text = message
            };

            using (var client = new SmtpClient())
            {
                client.ServerCertificateValidationCallback = (s, c, h, e) => true;
                client.Connect("smtp.gmail.com", 465, SecureSocketOptions.Auto);
                client.Authenticate("*****@*****.**", "gpr_m7_1718");
                client.Send(msg);
                client.Disconnect(true);
            }
            return(Task.CompletedTask);
        }
Exemple #6
0
 private void Send(MimeMessage mailMessage)
 {
     using (var client = new SmtpClient())
     {
         try
         {
             client.Connect(_emailConfig.SmtpServer, _emailConfig.Port, true);
             client.AuthenticationMechanisms.Remove("XOAUTH2");
             client.Authenticate(_emailConfig.UserName, _emailConfig.Password);
             client.Send(mailMessage);
         }
         catch
         {
             //log an error message or throw an exception or both.
             throw;
         }
         finally
         {
             client.Disconnect(true);
             client.Dispose();
         }
     }
 }
Exemple #7
0
        //Sends given mail
        public async Task SendMailAsync(EMailModel mail)
        {
            var message = new MimeMessage();

            message.From.Add(new MailboxAddress(mail.FromName, mail.FromAddress));
            message.To.Add(new MailboxAddress(mail.ToName, mail.ToAddress));
            message.Subject = mail.Subject;

            message.Body = new TextPart(TextFormat.Html)
            {
                Text = mail.Content
            };

            using (var emailClient = new SmtpClient())
            {
                emailClient.Connect(_config["EMailConfiguration:SmtpServer"], Convert.ToInt32(_config["EMailConfiguration:SmtpPort"]), true);
                emailClient.AuthenticationMechanisms.Remove("XOAUTH2");
                emailClient.Authenticate(_config["EMailConfiguration:SmtpUsername"], _config["EMailConfiguration:SmtpPassword"]);
                await emailClient.SendAsync(message);

                emailClient.Disconnect(true);
            }
        }
Exemple #8
0
        public async void Send(string emailRecipient, string nameRecipient, string messageText, string subject, bool copyAdmins)
        {
            var message = FormatEmail(emailRecipient, nameRecipient, messageText, subject, copyAdmins);

            try
            {
                using (var client = new SmtpClient())
                {
                    client.ServerCertificateValidationCallback = (s, c, h, e) => true;
                    client.Connect(_settings.HostName, _settings.Port, true);

                    client.Authenticate(_settings.Username, _settings.Password);

                    await client.SendAsync(message);

                    client.Disconnect(true);
                }
            }
            catch (System.Exception)
            {
                //v2 implementar log para exceptions
            }
        }
        public async Task SendEmailAsync()
        {
            foreach (var item in _notificationRepository.EmailList())
            {
                _mailRequest.Body    = _notificationMail.Body(_notificationRepository.UserName(item));
                _mailRequest.Subject = _notificationMail.Title();
                _mailRequest.ToEmail = _notificationMail.To(item);

                var email = new MimeMessage();
                email.Sender = MailboxAddress.Parse(_mailSettings.Mail);
                email.To.Add(MailboxAddress.Parse(_mailRequest.ToEmail));
                email.Subject = _mailRequest.Subject;
                var builder = new BodyBuilder();
                builder.HtmlBody = _mailRequest.Body;
                email.Body       = builder.ToMessageBody();
                using var smtp   = new SmtpClient();
                smtp.Connect(_mailSettings.Host, _mailSettings.Port, SecureSocketOptions.StartTls);
                smtp.Authenticate(_mailSettings.Mail, _mailSettings.Password);
                await smtp.SendAsync(email);

                smtp.Disconnect(true);
            }
        }
        private static async Task <string> SendingEmailAsync(MailBox mailBox)
        {
            try
            {
                using (var client = new SmtpClient())
                {
                    client.Connect(MailConfig.HostUri, MailConfig.PrimaryPort, SecureSocketOption.GetSecureSocketOptions());
                    if (MailConfig.RequireAuthentication)
                    {
                        client.Authenticate(MailConfig.UserName, MailConfig.Password);
                    }

                    await client.SendAsync(mailBox.MimeMessage);

                    client.Disconnect(true);
                }
                return(Constant.True);
            }
            catch (Exception ex)
            {
                return(ex.InnerException.ToString());
            }
        }
Exemple #11
0
        public void Enviar(string destinatario, string assunto, string mensagemHtml)
        {
            var message = new MimeMessage();

            message.From.Add(new MailboxAddress(configuracaoEmail.NomeRemetente, configuracaoEmail.EmailRemetente));
            message.To.Add(new MailboxAddress(destinatario));
            message.Subject = assunto;

            message.Body = new TextPart("html")
            {
                Text = mensagemHtml
            };

            using (var client = new SmtpClient())
            {
                client.Connect(configuracaoEmail.ServidorSmtp, configuracaoEmail.Porta, configuracaoEmail.UsarTls);

                client.Authenticate(configuracaoEmail.Usuario, configuracaoEmail.Senha);

                client.Send(message);
                client.Disconnect(true);
            }
        }
Exemple #12
0
        public void Notify(ISubscriber subscriber, Sweepstakes sweepstakes, Contestant winner)
        {
            StringBuilder name    = new StringBuilder();
            var           message = new MimeMessage();

            message.From.Add(new MailboxAddress(sweepstakes.Name, APIKeys.Email));
            message.To.Add(new MailboxAddress("Marketing Firm", subscriber.EmailAddress));
            message.Subject = "Sweepstakes Winner Announced!";
            message.Body    = new TextPart("plain")
            {
                Text = @"Hello,

The winner of the sweepstakes is " + winner.FirstName + " " + winner.LastName + "."
            };

            using (var client = new SmtpClient())
            {
                client.Connect("smtp.gmail.com", 587, false);
                client.Authenticate(APIKeys.Email, APIKeys.Password);
                client.Send(message);
                client.Disconnect(true);
            }
        }
Exemple #13
0
        public void EmailWinner()
        {
            {
                var message = new MimeMessage();
                message.From.Add(new MailboxAddress("The Head Honcho", "*****@*****.**"));
                message.To.Add(new MailboxAddress(contestant.FirstName + " " + contestant.LastName, contestant.EmailAddress));
                message.Subject = "You are the winner";

                message.Body = new TextPart("plain")
                {
                    Text = @"Hey,

                    I just wanted to let you know that you won the sweepstakes! Going to Vegas, baby!"
                };

                using (var client = new SmtpClient())
                {
                    client.ServerCertificateValidationCallback = (s, c, h, e) => true;
                    client.Send(message);
                    client.Disconnect(true);
                }
            }
        }
Exemple #14
0
 private void Send(MimeMessage message)
 {
     using (var c = new SmtpClient())
     {
         try
         {
             c.Connect("smtp.gmail.com", 465, true);
             c.AuthenticationMechanisms.Remove("XOAUTH2");
             c.Authenticate(config.UserName, config.Password);
             System.Console.WriteLine(config.UserName);
             c.Send(message);
         }
         catch (System.Exception)
         {
             throw;
         }
         finally
         {
             c.Disconnect(true);
             c.Dispose();
         }
     }
 }
        public static void SendMail_Gmail(string to, string asunto, string body)
        {
            //otro modo
            var mailMessage = new MimeMessage();

            mailMessage.From.Add(new MailboxAddress("Reportes Covid", "*****@*****.**"));

            mailMessage.To.Add(new MailboxAddress("", to));
            mailMessage.Subject = asunto;
            mailMessage.Body    = new TextPart("html")
            {
                Text = body
            };

            using (var smtpClient = new SmtpClient())
            {
                smtpClient.Connect("smtp.gmail.com", 465, true);
                //Ingresar Contrasena
                smtpClient.Authenticate("*****@*****.**", "EPEJXX103");
                smtpClient.Send(mailMessage);
                smtpClient.Disconnect(true);
            }
        }
Exemple #16
0
        public static void SendEmail(string emailTo, string subject, string body, string toAddressTitle)
        {
            var mimeMessage = new MimeMessage();

            mimeMessage.From.Add(new MailboxAddress(FROM_ADDRESS_TITLE, EMAIL));
            mimeMessage.To.Add(new MailboxAddress(toAddressTitle, emailTo));
            mimeMessage.Subject = subject;
            mimeMessage.Body    = new TextPart("plain")
            {
                Text = body
            };

            using (var client = new SmtpClient())
            {
                client.Connect(SMTP_SERVER, SMTP_NUMBER_NUMBER, false);
                // Note: only needed if the SMTP server requires authentication
                // Error 5.5.1 Authentication
                client.Authenticate(EMAIL, EMAIL_PASSWORD);
                client.Send(mimeMessage);
                Console.WriteLine("The mail has been sent successfully !!");
                client.Disconnect(true);
            }
        }
Exemple #17
0
        public static void SendPlainText(string subject, string text)
        {
            if (!EmailConfig.IsValid())
            {
                throw new Exception("邮件配置不正确");
            }
            var message = new MimeMessage();

            message.From.Add(new MailboxAddress("cx-auto-sign", EmailConfig.SmtpUsername));
            message.To.Add(new MailboxAddress("cx-auto-sign", EmailConfig.Email));
            message.Subject = subject;

            message.Body = new TextPart("plain")
            {
                Text = text
            };

            using var client = new SmtpClient();
            client.Connect(EmailConfig.SmtpHost, EmailConfig.SmtpPort, true);
            client.Authenticate(EmailConfig.SmtpUsername, EmailConfig.SmtpPassword);
            client.Send(message);
            client.Disconnect(true);
        }
Exemple #18
0
        private static void SendEmail(MimeMessage mail)
        {
            using (var client = new SmtpClient())
            {
                // XXX - Should this be a little different?
                client.ServerCertificateValidationCallback = (s, c, h, e) => true;

                client.Connect("smtp.mailgun.org", 587, false);
                client.AuthenticationMechanisms.Remove("XOAUTH2");
                client.Authenticate(Properties.Settings.Default.Username,
                                    Properties.Settings.Default.Password);
                try
                {
                    client.Send(mail);
                }
                catch (Exception)
                {
                    //TODO catch Exception;
                }

                client.Disconnect(true);
            }
        }
Exemple #19
0
        public async Task SendEmailAsync(string emailTo, string subject, string htmlMessage)
        {
            var email = new MimeMessage();

            email.Sender = MailboxAddress.Parse(_mailSettings.Mail);
            email.To.Add(MailboxAddress.Parse(emailTo));
            email.Subject = subject;

            var builder = new BodyBuilder
            {
                HtmlBody = htmlMessage
            };

            email.Body = builder.ToMessageBody();

            using var smtp = new SmtpClient();
            smtp.Connect(_mailSettings.Host, _mailSettings.Port, MailKit.Security.SecureSocketOptions.StartTls);
            smtp.Authenticate(_mailSettings.Mail, _mailSettings.Password);

            await smtp.SendAsync(email);

            smtp.Disconnect(true);
        }
Exemple #20
0
        public void SendEmail(MimeMessage message)
        {
            using (SmtpClient client = new SmtpClient())
            {
                if (Secrets.EmailServer == EmailSenderServerEnum.Rackspace)
                {
                    client.CheckCertificateRevocation = false;
                    client.SslProtocols = SslProtocols.Tls;
                }

                try
                {
                    client.Connect(Secrets.Host, Secrets.Port, MailKit.Security.SecureSocketOptions.SslOnConnect);
                    client.Authenticate(Secrets.SenderEmail, Secrets.SenderPassword);
                    client.Send(message);
                    client.Disconnect(true);
                }
                catch (Exception e)
                {
                    throw new Exception("There was a problem with either connecting or authenticating with the client", e);
                }
            }
        }
        public void Send()
        {
            if (_receivers.Count == 0)
            {
                throw new InvalidOperationException("empty receiver");
            }
            //create message
            var mimeMessage = new MimeMessage();

            mimeMessage.From.Add(sender.ToFrom());
            mimeMessage.To.AddRange(_receivers.ToMailAddresses());
            mimeMessage.Subject = subject;
            mimeMessage.Body    = message?.Body;
            //简历链接,发送
            using (var client = new SmtpClient())
            {
                client.ServerCertificateValidationCallback = (s, c, h, e) => true;
                client.Connect(Smtp.MailHost, Smtp.Port, useSsl: true);
                client.Authenticate(Smtp.MailUserName, Smtp.MailPassWord);
                client.Send(mimeMessage);
                client.Disconnect(true);
            }
        }
Exemple #22
0
        public IActionResult sendEmail(string name, string email, string content)
        {
            MimeMessage    message = new MimeMessage();
            MailboxAddress from    = new MailboxAddress(name, email);

            message.From.Add(from);
            MailboxAddress to = new MailboxAddress("Portfolio", "*****@*****.**");

            message.To.Add(to);
            message.Subject = "Email from Portfolio site";
            BodyBuilder bod = new BodyBuilder();

            bod.TextBody = content;
            message.Body = bod.ToMessageBody();
            SmtpClient client = new SmtpClient();

            client.Connect("smtp.gmail.com", 587, SecureSocketOptions.StartTls);
            client.Authenticate("*****@*****.**", "Crawler47!");
            client.Send(message);
            client.Disconnect(true);
            client.Dispose();
            return(View("Index"));
        }
Exemple #23
0
        public Task SendEmail(string subject, string to, string body)
        {
            return(Task.Run(() =>
            {
                var message = new MimeMessage();
                message.From.Add(new MailboxAddress(prihlaseny_uzivatel, prihlaseny_uzivatel));
                message.To.Add(new MailboxAddress(to, to));
                message.Subject = subject;
                message.Body = new TextPart(body);
                message.Date = DateTime.Now;

                using (var client = new SmtpClient())
                {
                    client.Connect("smtp.gmail.com", 587, true);

                    // Note: only needed if the SMTP server requires authentication
                    client.Authenticate(prihlaseny_uzivatel, prihlaseny_uzivatel_heslo);

                    client.Send(message);
                    client.Disconnect(true);
                }
            }));
        }
Exemple #24
0
        public string SendMail(EmailModel model)
        {
            EmailMessage message = new EmailMessage
            {
                Sender   = new MailboxAddress("Self", _notificationMetadata.Sender),
                Reciever = new MailboxAddress("Self", model.Reciever),
                Subject  = "Welcome",
                Content  = "Hello World!"
            };
            var mimeMessage = CreateMimeMessageFromEmailMessage(message);

            System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            using (SmtpClient smtpClient = new SmtpClient())
            {
                smtpClient.Connect(_notificationMetadata.SmtpServer,
                                   _notificationMetadata.Port, true);
                smtpClient.Authenticate(_notificationMetadata.UserName,
                                        _notificationMetadata.Password);
                smtpClient.Send(mimeMessage);
                smtpClient.Disconnect(true);
            }
            return("Email sent successfully");
        }
Exemple #25
0
        public void SendMail(String userId, String msg, String to)
        {
            // _userManager.GetUserId(HttpContext.User)


            var message = new MimeMessage();

            message.From.Add(new MailboxAddress("*****@*****.**"));
            message.To.Add(new MailboxAddress(to));
            message.Subject = "Ticket Purchase Information";
            message.Body    = new TextPart("plain")
            {
                Text = msg
            };
            using (var client = new SmtpClient())
            {
                client.Connect("smtp.gmail.com", 587, false);
                client.Authenticate("*****@*****.**", "Cs308proje");

                client.Send(message);
                client.Disconnect(true);
            }
        }
Exemple #26
0
        public async Task SendAsync(string subject, string htmlMessage)
        {
            var message = new MimeMessage();

            message.From.Add(new MailboxAddress(options.Name, options.Email));
            message.To.AddRange(Recipients.Select(recipient =>
                                                  new MailboxAddress(recipient.Name, recipient.Address)));
            message.Subject = subject;
            message.Body    = new BodyBuilder {
                HtmlBody = htmlMessage
            }.ToMessageBody();

            using (var client = new SmtpClient())
            {
                client.Connect(options.Host, options.Port, options.UseSsl);
                client.AuthenticationMechanisms.Remove("XOAUTH2");
                client.Authenticate(options.Username, options.Password);

                await client.SendAsync(message);

                client.Disconnect(true);
            }
        }
        private void SendEmail(MimeMessage mailMessage)
        {
            using (var client = new SmtpClient())
            {
                try
                {
                    client.Connect(_emailConfiguration.SmtpServer, _emailConfiguration.Port, true);
                    client.AuthenticationMechanisms.Remove("XOAUTH2");
                    client.Authenticate(_emailConfiguration.UserName, _emailConfiguration.Password);

                    client.Send(mailMessage);
                }
                catch
                {
                    throw;
                }
                finally
                {
                    client.Disconnect(true);
                    client.Dispose();
                }
            }
        }
Exemple #28
0
        public void SendEmail(string email, string subject, string message)
        {
            var emailMessage = new MimeMessage();

            email = "*****@*****.**";
            emailMessage.From.Add(new MailboxAddress("Site Manager", email));
            emailMessage.To.Add(new MailboxAddress("", email));
            emailMessage.Subject = subject;
            emailMessage.Body    = new TextPart(MimeKit.Text.TextFormat.Html)
            {
                Text = message
            };

            using (var client = new SmtpClient())
            {
                //await client.ConnectAsync("smtp.yandex.ru", 25, false);
                client.Connect("smtp.gmail.com", 465, true);
                client.Authenticate(email, "");
                client.Send(emailMessage);

                client.Disconnect(true);
            }
        }
        public async Task SendAsync(MailRequest request)
        {
            try
            {
                var email = new MimeMessage();
                email.Sender = MailboxAddress.Parse(request.From ?? _mailSettings.From);
                email.To.Add(MailboxAddress.Parse(request.To));
                email.Subject = request.Subject;
                var builder = new BodyBuilder();
                builder.HtmlBody = request.Body;
                email.Body       = builder.ToMessageBody();
                using var smtp   = new SmtpClient();
                smtp.Connect(_mailSettings.Host, _mailSettings.Port, SecureSocketOptions.StartTls);
                smtp.Authenticate(_mailSettings.UserName, _mailSettings.Password);
                await smtp.SendAsync(email);

                smtp.Disconnect(true);
            }
            catch (System.Exception ex)
            {
                _logger.LogError(ex.Message, ex);
            }
        }
Exemple #30
0
 private async Task Send(MimeMessage message)
 {
     using (var clientSmtp = new SmtpClient())
     {
         try
         {
             clientSmtp.Connect(_emailConfig.SmtpServer, _emailConfig.Port, true);
             clientSmtp.AuthenticationMechanisms.Remove("XOAUTH2");
             clientSmtp.Timeout = 30000;
             clientSmtp.Authenticate(_emailConfig.UserName, _emailConfig.Password);
             await clientSmtp.SendAsync(message);
         }
         catch
         {
             throw;
         }
         finally
         {
             clientSmtp.Disconnect(true);
             clientSmtp.Dispose();
         }
     }
 }