public async Task <AjaxResult> SendConfirmMail(SendMailDto dto) { if (!ModelState.IsValid) { return(new AjaxResult("提交信息验证失败", AjaxResultType.Error)); } if (!_verifyCodeService.CheckCode(dto.VerifyCode, dto.VerifyCodeId)) { return(new AjaxResult("验证码错误,请刷新重试", AjaxResultType.Error)); } User user = await _userManager.FindByEmailAsync(dto.Email); if (user == null) { return(new AjaxResult("发送激活邮件失败:用户不存在", AjaxResultType.Error)); } if (user.EmailConfirmed) { return(new AjaxResult("Email已激活,无需再次激活", AjaxResultType.Info)); } string code = await _userManager.GenerateEmailConfirmationTokenAsync(user); code = UrlBase64ReplaceChar(code); string url = $"{Request.Scheme}://{Request.Host}/#/passport/confirm-email?userId={user.Id}&code={code}"; string body = $"亲爱的用户 <strong>{user.NickName}</strong>[{user.UserName}],你好!<br>" + $"欢迎注册,激活邮箱请 <a href=\"{url}\" target=\"_blank\"><strong>点击这里</strong></a><br>" + $"如果上面的链接无法点击,您可以复制以下地址,并粘贴到浏览器的地址栏中打开。<br>" + $"{url}<br>" + $"祝您使用愉快!"; await SendMailAsync(user.Email, "柳柳软件 注册邮箱激活邮件", body); return(new AjaxResult("激活Email邮件发送成功")); }
public SendMailDto sendEmail(SendMailDto mail) { try { MailMessage mailMessage = new MailMessage(); mailMessage.From = new MailAddress(_config["EmailSender"]); mailMessage.To.Add(_config["EmailReceiver"]); mailMessage.IsBodyHtml = true; mailMessage.Subject = mail.Subject; string content = "Name: " + mail.Name; content += "<br/> Address: " + mail.EmailAddress; content += "<br/> Message: " + mail.Message; Console.WriteLine("Content " + content); mailMessage.Body = content; SmtpClient smtpClient = new SmtpClient(" smtp.gmail.com"); smtpClient.Port = 587; NetworkCredential networkCredential = new NetworkCredential(_config["EmailSender"], _config["EmailSenderPassword"]); smtpClient.UseDefaultCredentials = false; smtpClient.Credentials = networkCredential; smtpClient.EnableSsl = true; smtpClient.Send(mailMessage); } catch (Exception e) { Console.WriteLine("In exception"); Console.WriteLine(e); } return(mail); }
public async Task <AjaxResult> SendResetPasswordMail(SendMailDto dto) { if (!ModelState.IsValid) { return(new AjaxResult("提交数据验证失败", AjaxResultType.Error)); } if (!_verifyCodeService.CheckCode(dto.VerifyCode, dto.VerifyCodeId)) { return(new AjaxResult("验证码错误,请刷新重试", AjaxResultType.Error)); } User user = await _userManager.FindByEmailAsync(dto.Email); if (user == null) { return(new AjaxResult("用户不存在", AjaxResultType.Error)); } string token = await _userManager.GeneratePasswordResetTokenAsync(user); token = UrlBase64ReplaceChar(token); IEmailSender sender = HttpContext.RequestServices.GetService <IEmailSender>(); string url = $"{Request.Scheme}://{Request.Host}/#/passport/reset-password?userId={user.Id}&token={token}"; string body = $"亲爱的用户 <strong>{user.NickName}</strong>[{user.UserName}],您好!<br>" + $"欢迎使用柳柳软件账户密码重置功能,请 <a href=\"{url}\" target=\"_blank\"><strong>点击这里</strong></a><br>" + $"如果上面的链接无法点击,您可以复制以下地址,并粘贴到浏览器的地址栏中打开。<br>" + $"{url}<br>" + $"祝您使用愉快!"; await sender.SendEmailAsync(user.Email, "柳柳软件 重置密码邮件", body); return(new AjaxResult("密码重置邮件发送成功")); }
public async Task <IActionResult> SendResetPasswordMail([FromBody] SendMailDto dto) { if (!ModelState.IsValid) { return(Json(new AjaxResult("提交数据验证失败", AjaxResultType.Error))); } //todo: 校验验证码 User user = await _userManager.FindByEmailAsync(dto.Email); if (user == null) { return(Json(new AjaxResult("用户不存在", AjaxResultType.Error))); } string token = await _userManager.GeneratePasswordResetTokenAsync(user); token = UrlBase64ReplaceChar(token); IEmailSender sender = ServiceLocator.Instance.GetService <IEmailSender>(); string url = $"{Request.Scheme}://{Request.Host}/#/identity/reset-password?userId={user.Id}&token={token}"; string body = $"亲爱的用户 <strong>{user.NickName}</strong>[{user.UserName}],您好!<br>" + $"欢迎使用柳柳软件账户密码重置功能,请 <a href=\"{url}\" target=\"_blank\"><strong>点击这里</strong></a><br>" + $"如果上面的链接无法点击,您可以复制以下地址,并粘贴到浏览器的地址栏中打开。<br>" + $"{url}<br>" + $"祝您使用愉快!"; await sender.SendEmailAsync(user.Email, "柳柳软件 重置密码邮件", body); return(Json(new AjaxResult("密码重置邮件发送成功"))); }
public IActionResult ContactUs(SendMailDto sendMailDto) { if (!ModelState.IsValid) { return(View("Index")); } try { MailMessage mail = new MailMessage(); // you need to enter your mail address mail.From = new MailAddress("*****@*****.**"); //To Email Address - your need to enter your to email address mail.To.Add("*****@*****.**"); mail.Subject = sendMailDto.Subject; mail.IsBodyHtml = true; string content = "Name : " + sendMailDto.Name; content += "<br/> Email : " + sendMailDto.Email; content += "<br/> Phone Number : " + sendMailDto.PhoneNumber; content += "<br/> Subject : " + sendMailDto.Subject; content += "<br/> Message : " + sendMailDto.Message; mail.Body = content; //create SMTP instant //you need to pass mail server address and you can also specify the port number if you required SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587); //Create nerwork credential and you need to give from email address and password NetworkCredential networkCredential = new NetworkCredential("*****@*****.**", "Pass Of Sender Email"); smtpClient.UseDefaultCredentials = false; smtpClient.Credentials = networkCredential; smtpClient.Port = 587; // this is default port number - you can also change this smtpClient.EnableSsl = true; // if ssl required you need to enable it smtpClient.Send(mail); ViewBag.Message = "شكرا لتواصلك معنا "; // now i need to create the from ModelState.Clear(); } catch (Exception ex) { //If any error occured it will show ViewBag.Message = ex.Message.ToString(); } return(View("Index")); }
public async Task <IActionResult> Send(long id, [FromBody] SendMailDto sendMail) { Template template; try { template = await context.Set <Template>() .Include(x => x.Mail) .FirstAsync(x => x.User.Token == sendMail.Token && x.Id == id); } catch { throw new TemplateNotFoundException(); } var secret = configuration.GetValue <string>("PasswordSecret"); var stubble = new StubbleBuilder().Build(); var from = new MailAddress(template.Mail.EmailAddress, template.Mail.Name); var password = encryption.Decrypt(template.Mail.Password, secret); foreach (var recipient in sendMail.Recipients) { var subject = await stubble.RenderAsync(template.Subject, recipient.Args); var body = await stubble.RenderAsync(template.Content, recipient.Args); var to = new MailAddress(recipient.Email); var message = new MailMessage(from, to) { Subject = subject, Body = body, BodyEncoding = Encoding.UTF8, IsBodyHtml = template.IsHtml }; using var smtp = new SmtpClient(template.Mail.Host, template.Mail.Port) { DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, EnableSsl = template.Mail.EnableSsl, Credentials = new NetworkCredential(template.Mail.EmailAddress, password) }; try { await smtp.SendMailAsync(message); } catch (Exception ex) { throw new BusinessException("smtp-error", $"Something happened when sending the email to {recipient.Email} via SMTP: {ex.Message}", ex); } } return(Ok()); }
public IActionResult ContactUs(SendMailDto sendMailDto) { if (!ModelState.IsValid) { return(View()); } try { MailMessage mail = new MailMessage(); // you need to enter your mail address mail.From = new MailAddress("*****@*****.**"); //To Email Address - your need to enter your to email address mail.To.Add("*****@*****.**"); mail.Subject = sendMailDto.Subject; //you can specify also CC and BCC - i will skip this //mail.CC.Add(""); //mail.Bcc.Add(""); mail.IsBodyHtml = true; string content = "Name : " + sendMailDto.Name; content += "<br/> Message : " + sendMailDto.Message; mail.Body = content; //create SMTP instant //you need to pass mail server address and you can also specify the port number if you required SmtpClient smtpClient = new SmtpClient("mail.example.com"); //Create nerwork credential and you need to give from email address and password NetworkCredential networkCredential = new NetworkCredential("*****@*****.**", "password"); smtpClient.UseDefaultCredentials = false; smtpClient.Credentials = networkCredential; smtpClient.Port = 25; // this is default port number - you can also change this smtpClient.EnableSsl = false; // if ssl required you need to enable it smtpClient.Send(mail); ViewBag.Message = "Mail Send"; // now i need to create the from ModelState.Clear(); } catch (Exception ex) { //If any error occured it will show ViewBag.Message = ex.Message.ToString(); } return(View()); }
public IActionResult GetNotification([FromBody] SendMailDto request) { SendMail mail = new SendMail() { SendDate = request.SendDate, AccountId = request.AccountId }; _mailRepository.Add(mail); return(Ok()); }
public IActionResult CreateNotification([FromBody] SendMailDto request) { SendMail mail = new SendMail() { SendDate = request.SendDate, InvoiceId = request.InvoiceId }; _mailRepository.Add(mail); return(Ok()); }
public IActionResult SendEmail([FromBody] SendMailDto sendMailData) { try { _webFileService.SendLinkToEmailAdress(sendMailData); return(Ok()); } catch (Exception ex) { return(BadRequest(new { message = ex.Message })); } }
public void SendLinkToEmailAdress(SendMailDto sendMailData) { string sendTo = sendMailData.sendToEmail; string subject = "Somebody shared you new file!"; StringBuilder message = new StringBuilder(); message.Append("<h1>Hello</h1>"); message.Append("<h2>You just got new file, check it out"); message.Append("<a href=\""); message.Append(sendMailData.link); message.Append("\">here!</a>"); message.Append("</h2>"); this.SendEmail(sendTo, message.ToString(), subject); }
public void Send(SendMailDto dto) { var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential("*****@*****.**", "Lozinka123") }; var message = new MailMessage("*****@*****.**", dto.SendTo); message.Subject = dto.Subject; message.Body = dto.Content; message.IsBodyHtml = true; smtp.Send(message); }
public ActionResult Index(SendMailDto sendMailDto) { if (ModelState.IsValid) { EmailContact econact = new EmailContact { Name = sendMailDto.Name, Message = sendMailDto.Message, Subject = sendMailDto.Subject }; bool status = _contact.SendEmail(econact); string email = ""; //bool s = _contact.EmailValidation(email); return(View()); } return(View()); }
public IActionResult ContactUs(SendMailDto sendMail) { if (!ModelState.IsValid) { return(View()); } try { MailMessage mail = new MailMessage(); mail.From = new MailAddress("*****@*****.**"); mail.To.Add("*****@*****.**"); mail.Subject = sendMail.Subject; mail.IsBodyHtml = true; string content = "Name : " + sendMail.Name; content += "<br /> Message :" + sendMail.Message; mail.Body = content; SmtpClient smtp = new SmtpClient("smtp.gmail.com"); NetworkCredential networkCredential = new NetworkCredential("*****@*****.**", "Skiing0709!"); smtp.UseDefaultCredentials = false; smtp.Credentials = networkCredential; smtp.Port = 587; smtp.EnableSsl = true; smtp.Send(mail); ViewBag.Message = "Message sent!"; } catch (Exception ex) { ViewBag.Message = ex.Message.ToString(); } return(View()); }
public async Task <string> ForgetPassword(string emailAddress, string passwordResetCallbackUrl) { var user = await _userManager.FindByEmailAsync(emailAddress); if (user == null) { // Don't reveal that the user does not exist return("Recover link is send to your email"); } var code = await _userManager.GeneratePasswordResetTokenAsync(user); var encodedUserId = await _encryptionDecryptionService.EncryptString(user.Id.ToString()); var callbackUrl = System.Web.HttpUtility.UrlDecode(System.Web.HttpUtility.UrlEncode(passwordResetCallbackUrl.TrimEnd('/') + "?userKey=" + encodedUserId + "&token=" + code)); var message = "Please reset your password by clicking here: <a href=\"" + callbackUrl + "\">link</a>"; var emailList = new System.Collections.Generic.List <string>(); emailList.Add(emailAddress); var mailModel = new SendMailDto { Subject = "Sunrise Bank forget password", Body = message, EmailAddresses = emailList }; try { await _emailService.ForgetPasswordMailHelper(mailModel); } catch (Exception) { return("Server response with an error, please try again later."); } // If we got this far, something failed, redisplay form return("Password recovery email successfully send at " + emailAddress + ". Check your email for the confirmation link."); }
public async Task <IActionResult> Send([FromBody] SendMailDto model) { var emailes = _mailingRepository.Table.Select(x => x.Email); if (model.IsForOnlyRegisterUsers) { var usersSubscribedEmails = _userManager.Users.Select(x => x.Email).Intersect(emailes); foreach (var email in usersSubscribedEmails) { await _emailSender.SendEmailAsync(_configuration["EmailCredential:Email"], email, model.Subject, model.Body); } return(Ok("Success")); } foreach (var email in emailes) { await _emailSender.SendEmailAsync(_configuration["EmailCredential:Email"], email, model.Subject, model.Body); } return(Ok("Success")); }
public IActionResult SendMail(SendMailDto mail) { return(Ok(_emailService.sendEmail(mail))); }
public async Task ForgetPasswordMailHelper(SendMailDto mailInput) { await this.SendEmail(mailInput); }
public async Task UserVerificationMailHelper(SendMailDto mailInput) { await this.SendEmail(mailInput); }
public virtual async Task <RegisterOutput> Register(RegisterInput input) { try { CheckErrors(await _userManager.CheckDuplicateUsernameOrEmailAddressAsync(1, input.PhoneNumber, input.EmailAddress)); var user = await _userRegistrationManager.RegisterAsync( input.FirstName + " " + input.LastName, input.LastName, input.EmailAddress, input.PhoneNumber //phone number become a user name ); //register user extra information var additionalUserInfo = new ApplicationUser { UserId = user.Id, FirstName = input.FirstName, MiddleName = input.MiddleName, LastName = input.LastName, PrimaryEmailAddress = input.EmailAddress, PrimaryMobileNumber = input.PhoneNumber, IsVerified = false, IsActive = false, IsPasswordCreated = false, IsSuspended = false, }; var reason = "User Registration : Registration begin with basic information, Registered User Id is : " + user.Id; using (_reasonProvider.Use(reason)) { await _applicationUserReposatory.InsertAsync(additionalUserInfo); } var isEmailConfirmationRequiredForLogin = await SettingManager.GetSettingValueAsync <bool>(AbpZeroSettingNames.UserManagement.IsEmailConfirmationRequiredForLogin); var verificationEmailToken = await _userManager.GenerateEmailConfirmationTokenAsync(user); var verificationPhoneTokne = await _userManager.GenerateChangePhoneNumberTokenAsync(user, input.PhoneNumber); try { var message = "Your verification code is " + verificationPhoneTokne + ". Thank you"; var emailList = new System.Collections.Generic.List <string>(); emailList.Add(additionalUserInfo.PrimaryEmailAddress); var mailModel = new SendMailDto { Subject = "Sunrise Bank User Registration", Body = message, EmailAddresses = emailList }; await _emailService.UserVerificationMailHelper(mailModel); } catch (Exception) { throw new UserFriendlyException("Server response with an exception. Please try again."); } await CurrentUnitOfWork.SaveChangesAsync(); return(new RegisterOutput { CanLogin = user.IsActive && (user.IsEmailConfirmed || !isEmailConfirmationRequiredForLogin), IsSuccess = true, UserId = user.Id, RegisterMessage = "User Successfully registered", VerificationCode = "", VerificationEmailToken = verificationEmailToken, VerificationPhoneTokne = verificationPhoneTokne, }); } catch (Exception ex) { return(new RegisterOutput { CanLogin = false, IsSuccess = false, RegisterMessage = ex.Message }); } }
private async Task SendEmail(SendMailDto mailInput) { try { var encryptedEmailAddress = _configuration["EmailConfig:EncryptedEmailAddress"]; var encryptedPassword = _configuration["EmailConfig:EncryptedPassword"]; var host = _configuration["EmailConfig:Host"]; var port = _configuration["EmailConfig:Port"]; var enableSSL = _configuration["EmailConfig:EnableSSL"]; var defaultCCEmails = _configuration["EmailConfig:DefaultCCEmails"]; var defaultEmails = _configuration["EmailConfig:DefaultEmails"]; var defaultSubject = _configuration["EmailConfig:DefaultSubject"]; using (var client = new SmtpClient()) { var credential = new NetworkCredential { UserName = await _encryptionDecryptionService.DecryptString(encryptedEmailAddress), Password = await _encryptionDecryptionService.DecryptString(encryptedPassword) }; client.Credentials = credential; client.Host = host; client.EnableSsl = Convert.ToBoolean(enableSSL); //Try port 587 instead of 465. Port 465 is technically deprecated. client.Port = Convert.ToInt32(port); using (var emailMessage = new MailMessage()) { foreach (var email in mailInput.EmailAddresses) { emailMessage.To.Add(email); } emailMessage.From = new MailAddress(await _encryptionDecryptionService.DecryptString(encryptedEmailAddress)); if (_environment.IsDevelopment()) { foreach (var ccEmail in defaultCCEmails.Split(',')) { emailMessage.CC.Add(ccEmail); } } emailMessage.Subject = string.IsNullOrEmpty(mailInput.Subject)? defaultSubject : mailInput.Subject; emailMessage.Body = mailInput.Body; emailMessage.IsBodyHtml = true; // Include "Message-Id" header or your message will be treated as spam by Google. emailMessage.Headers.Add("Message-Id", String.Concat("<", DateTime.Now.ToString("yyMMdd"), ".", DateTime.Now.ToString("HHmmss"), "@amniltech.com")); client.Send(emailMessage); } } await Task.CompletedTask; } catch (Exception ex) { throw new UserFriendlyException(ex.Message); } }
public ActionResult Index() { SendMailDto mm = new SendMailDto(); return(View(mm)); }