public IResult SendMail(EmailSenderModel model)
 {
     try
     {
         var to      = model.To;
         var subject = model.Subject;
         var body    = model.Body;
         var mail    = new MailMessage();
         mail.To.Add(to);
         mail.Subject    = subject;
         mail.Body       = body;
         mail.From       = new MailAddress("*****@*****.**");
         mail.IsBodyHtml = false;
         var smtp = new SmtpClient
         {
             Port = 587,
             UseDefaultCredentials = false,
             EnableSsl             = true,
             Credentials           = new System.Net.NetworkCredential("*****@*****.**", "TR1923")
         };
         smtp.Host = "smtp.gmail.com";
         smtp.Send(mail);
         return(new SuccessResult("Mail send success"));
     }
     catch (Exception)
     {
         _loggerService.Error("Error to send mail");
         return(new ErrorResult("Error to send mail!"));
     }
 }
Exemplo n.º 2
0
        public bool SendMailSMTP(EmailSenderModel emailSenderModel)
        {
            try
            {
                var infoMail = _infoRepo.TableNoTracking.Where(x => x.InfoType == Data.Enum.InfoType.Email).FirstOrDefault();


                SmtpClient client = new SmtpClient(infoMail.SmtpEmail);
                client.UseDefaultCredentials = false;
                client.Credentials           = new NetworkCredential(infoMail.Email, infoMail.Password);
                client.Port = int.Parse(infoMail.PortEmail);

                MailMessage mailmsg = new MailMessage();
                mailmsg.From = new MailAddress(infoMail.Email);
                mailmsg.To.Add(emailSenderModel.Email);
                mailmsg.Body    = emailSenderModel.Message;
                mailmsg.Subject = emailSenderModel.Subject;

                client.Send(mailmsg);
                return(false);
            }
            catch
            {
                throw;
            }
        }
Exemplo n.º 3
0
 public IActionResult SendContact(EmailSenderModel emailSenderModel)
 {
     emailSenderModel.Message = "Tên liên hệ: " + emailSenderModel.FullName +
                                " Email liên hệ: " + emailSenderModel.Email +
                                " Điện thoại liên hệ: " + emailSenderModel.Phone +
                                "\n\n" + emailSenderModel.Message;
     _emailService.SendMailSMTP(emailSenderModel);
     return(RedirectToAction("Index"));
 }
Exemplo n.º 4
0
 public IActionResult SendContact(EmailSenderModel emailSenderModel)
 {
     emailSenderModel.Message = "Name: " + emailSenderModel.FullName +
                                " Email contact: " + emailSenderModel.Email +
                                " Phone contact: " + emailSenderModel.Phone +
                                "\n\n" + emailSenderModel.Message;
     _emailService.SendMailSMTP(emailSenderModel);
     return(RedirectToAction("Index"));
 }
        public IResult PasswordResetMail(ForgotPasswordDto forgotPasswordDto)
        {
            var result = CreatePasswordResetToken(forgotPasswordDto.Email);

            if (result.Success)
            {
                var user      = _userService.GetByEmail(forgotPasswordDto.Email);
                var link      = CreatePasswordResetLink(user.Id);
                var sendModel = new EmailSenderModel
                {
                    To      = forgotPasswordDto.Email,
                    Subject = "Password Reset",
                    Body    = "Click to link for reset password \n" + link,
                };

                _mailService.SendMail(sendModel);
                return(new SuccessResult("Send password reset mail!"));
            }
            return(new ErrorResult(result.Message));
        }