public IActionResult EMailSender(EMailListViewModel model, EMailModel m) { var s = m.Subject; var b = m.Body; var tut = _emailServices.GetAll(); SmtpClient client = new SmtpClient("smtp.gmail.com", 587); //Burası aynı kalacak client.Credentials = new NetworkCredential("*****@*****.**", ""); //<<<<<<<<<<<<< client.EnableSsl = true; MailMessage msj = new MailMessage(); //Yeni bir MailMesajı oluşturuyoruz foreach (var item in tut) { //hata veriyosa güncellemedeki gibi yapsam msj.From = new MailAddress(item.Email, item.NameSurname); //iletişim kısmında girilecek mail buaraya gelecektir msj.To.Add("*****@*****.**"); // <<<<<<<<<<<<<<<<<<<<<<< MailMessage msj1 = new MailMessage(); msj1.From = new MailAddress("*****@*****.**", "Haliç Teknoloji Portalı"); //<<<<<<<<<<<<<<<<< msj1.To.Add(item.Email); //Buraya iletişim sayfasında gelecek mail adresi gelecktir. msj1.Subject = s; msj1.Body = b; client.Send(msj1); } ViewBag.Succes = "teşekkürler Mailniz başarı bir şekilde gönderildi"; //Bu kısımlarda ise kullanıcıya bilgi vermek amacı ile olur return(Redirect("/Admin/EMailList")); }
public async Task <ActionResult> Contact(EMailModel model) { if (ModelState.IsValid) { try { var body = "<p>Email From: <bold>{0}</bold>" + "({1})</p><p>Message:</p><p>{2}</p>"; var svc = new EmailService(); var msg = new IdentityMessage() { Subject = "Contact From Blog Site", Body = string.Format(body, model.FromName, model.FromEmail, model.Body), Destination = "*****@*****.**" //Add your personal email here! }; await svc.SendAsync(msg); return(View()); } catch (Exception ex) { Console.WriteLine(ex.Message); await Task.FromResult(0); return(View(model)); } } else { return(View(model)); } }
public IActionResult NewsEmail([FromBody] EMailModel m) { try { SmtpClient client = new SmtpClient("smtp.gmail.com", 587); //Burası aynı kalacak client.Credentials = new NetworkCredential("*****@*****.**", ""); client.EnableSsl = true; MailMessage msj = new MailMessage(); //Yeni bir MailMesajı oluşturuyoruz msj.From = new MailAddress(m.Email, m.NameSurname); //iletişim kısmında girilecek mail buaraya gelecektir msj.To.Add("*****@*****.**"); //Buraya kendi mail adresimizi yazıyoruz<<<<<<<<<<<<<<<<<< //Bu kısımdan itibaren sizden kullanıcıya gidecek mail bilgisidir MailMessage msj1 = new MailMessage(); msj1.From = new MailAddress("*****@*****.**", "Haliç Teknoloji Portalı"); //<<<<<<<<<<< msj1.To.Add(m.Email); //Buraua iletişim sayfasında gelecek mail adresi gelecktir. msj1.Subject = "Haliç Hub Aboneliği"; msj1.Body = "Haliç Hub Teknoloji Portalına Aboneliğiniz Gerçekleşmiştir. Aramıza Hoşgeldiniz..."; client.Send(msj1); //aslında foreachla modelin içindekileri dolaşıp mesajı gönderebiliriz var entity = new EMail() { NameSurname = m.NameSurname, Email = m.Email }; _emailServices.Create(entity); ViewBag.Succes = "teşekkürler Mailniz başarı bir şekilde gönderildi"; //Bu kısımlarda ise kullanıcıya bilgi vermek amacı ile olur return(Redirect("/Haberler/" + TempData["Nurl"])); } catch (Exception) { ViewBag.Error = "Mesaj Gönderilken hata olıuştu"; //Bu kısımlarda ise kullanıcıya bilgi vermek amacı ile olur return(Redirect("/Halic/makaleler")); } }
public ActionResult List(EMailListModel model) { if (Request.IsAjaxRequest()) { IPagedList <EMail> list = _service.GetMails(model.PageIndex, model.PageSize, model.Ordering, model.From.Value, model.To.Value, model.Receiver); List <EMailModel> modelList = new List <EMailModel>(); foreach (EMail email in list) { EMailModel emailModel = Map <EMailModel>(email); if (this.IsDemo) { //E-Mail Addresses are masked on Demo site for security reasons //Eventhough ,they are random randomly generated , some users might send e-mails //to themselves for test purposes emailModel.Receivers = RegexHelper.MaskEmailAddress(emailModel.Receivers); } modelList.Add(emailModel); } return(DataTableResult(modelList, list.TotalCount, model.Draw)); } return(View(model)); }
public ActionResult ViewDetail() { EMailModel model = Map <EMailModel>(_service.GetById(int.Parse(Request.QueryString["id"]))); if (this.IsDemo) { model.Receivers = RegexHelper.MaskEmailAddress(model.Receivers); } return(View(model)); }
private EMailModel GenerateConfiramtionEmail(AppUser user) { var link = GenereateConfirimationEmailLink(user); EMailModel email = new EMailModel() { DestinationAddress = user.Email, MessegeBody = $"for confiramtion click in this <a href = 'http://movieuniverse.cloudapp.net:3000/verfication?email={user.Email}&key={link}' target = '_blanck'>link</a>", Subject = "Confirmation Message", }; return(email); }
//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); } }
public void SendEmail(EMailModel email) { using (MailMessage mail = new MailMessage()) { mail.From = new MailAddress("*****@*****.**"); mail.To.Add(email.DestinationAddress); mail.Subject = email.Subject; mail.Body = email.MessegeBody; mail.IsBodyHtml = true; SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587); try { smtp.Credentials = new NetworkCredential("*****@*****.**", "hrashq56$#"); smtp.EnableSsl = true; smtp.Send(mail); } catch (Exception ex) { int b = 5; } } }
public ActionResult Contact() { EMailModel model = new EMailModel(); return(View(model)); }
public async void SendEMailAsync([FromBody] EMailModel model) { await Task.Run(() => { if (model == null) { return; } #region Write Log var dtEntry = DateTime.Now; var address = baseAddress + ".SendEMail([FromBody]EMailModel model)"; var dic = LogBusiness.GetDictionary(); dic.Add(LogFieldName.FullyQualifiedFunctionName, address); var dicParams = LogBusiness.GetDictionary(); dicParams.Add(LogFieldName.Token, dicParams); LogBusiness.CustomLog(model.From, LogEvent.MethodStart, dic, dicParams); #endregion start: using (var smtp = new SmtpClient(MailSmtpHost)) { using (var message = new MailMessage()) { smtp.Credentials = new NetworkCredential(); smtp.Host = MailSmtpHost; smtp.Port = MailSmtpPort; smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.UseDefaultCredentials = false; message.IsBodyHtml = true; if (model.Retry == 0) { try { if (File.Exists(@"/Resources/yourMailPic.gif")) { message.AlternateViews.Add(CreateEmbeddedImage("/Resources/yourMailPic.gif")); } if (!string.IsNullOrEmpty(model.From)) { var fromList = model.From.Split('&'); message.From = new MailAddress(fromList[0], fromList[1]); } if (!string.IsNullOrEmpty(model.Subject)) { message.Subject = model.Subject; } if (!string.IsNullOrEmpty(model.Body)) { message.Body = model.Body; } if (!string.IsNullOrEmpty(model.To)) { var toList = model.To.Split(';'); foreach (var toRaw in toList) { var toRawList = toRaw.Split('&'); var addr = new MailAddress(toRawList[0], toRawList[1]); message.To.Add(addr); } } //CC's if (!string.IsNullOrEmpty(model.Cc)) { var ccMails = model.Cc.Split(';').ToArray(); foreach (var ccEmail in ccMails) { var ccRawList = ccEmail.Split('&'); var ccaddr = new MailAddress(ccRawList[0], ccRawList[1]); message.CC.Add(ccaddr); } } //BCC's if (!string.IsNullOrEmpty(model.Bcc)) { var bccMails = model.Bcc.Split(';').ToArray(); foreach (var bccEmail in bccMails) { var bccRawList = bccEmail.Split('&'); var bccaddr = new MailAddress(bccRawList[0], bccRawList[1]); message.Bcc.Add(bccaddr); } } //Attachment's if (model.EmailAttachments.Count > 0) { foreach (var attachment in model.EmailAttachments) { var attachmentMetaData = new Attachment(new MemoryStream(attachment.File), attachment.FileName, MediaTypeNames.Application.Octet); message.Attachments.Add(attachmentMetaData); } } model.SentDate = DateTime.Now; var mail = new Email { Subject = model.Subject, Bcc = model.Bcc, Cc = model.Cc, Body = model.Body, From = model.From, To = model.To, SmtpServer = MailSmtpHost }; foreach (var attachment in model.EmailAttachments) { var attach = new EmailAttachment { File = attachment.File, FileName = attachment.FileName }; mail.EmailAttachments.Add(attach); } _emailService.Add(mail); _emailService.Save(); var savePkId = mail.Id; var updateEmail = _emailService.GetAll().FirstOrDefault(x => x.Id == savePkId); try { smtp.Send(message); if (updateEmail == null) { return; } updateEmail.IsSent = true; updateEmail.SentDate = DateTime.Now; _emailService.Update(updateEmail); _emailService.Save(); } catch (Exception e) { if (updateEmail != null) { updateEmail.Exception = e.InnerException == null ? e.Message : e.Message + " --> " + e.InnerException.Message; updateEmail.LastTryDate = DateTime.Now; updateEmail.Retry = updateEmail.Retry++; _emailService.Update(updateEmail); _emailService.Save(); } } } catch (Exception ex) { #region Write Log dic = LogBusiness.GetDictionary(); dic.Add(LogFieldName.FullyQualifiedFunctionName, address); dic.Add(LogFieldName.ErrorMessage, ex.Message); dic.Add(LogFieldName.StackTrace, ex.StackTrace); LogBusiness.CustomLog(model.From, LogEvent.ErrorEvent, dic, dicParams); MailSmtpHost = MailSmtpHost2; goto start; #endregion } finally { #region Write Log dic = LogBusiness.GetDictionary(); dic.Add(LogFieldName.FullyQualifiedFunctionName, address); dic.Add(LogFieldName.TimeElapsed, ((int)(DateTime.Now - dtEntry).TotalMilliseconds).ToString()); LogBusiness.CustomLog(model.From, LogEvent.MethodEnd, dic, dicParams); #endregion } } else { try { if (!string.IsNullOrEmpty(model.From)) { var fromList = model.From.Split('&'); message.From = new MailAddress(fromList[0], fromList[1]); } if (!string.IsNullOrEmpty(model.Subject)) { message.Subject = model.Subject; } if (!string.IsNullOrEmpty(model.Body)) { message.Body = model.Body; } if (!string.IsNullOrEmpty(model.To)) { var toList = model.To.Split(';'); foreach (var toRaw in toList) { var toRawList = toRaw.Split('&'); var addr = new MailAddress(toRawList[0], toRawList[1]); message.To.Add(addr); } } //CC's if (!string.IsNullOrEmpty(model.Cc)) { var ccMails = model.Cc.Split(';').ToArray(); foreach (var ccEmail in ccMails) { var ccRawList = ccEmail.Split('&'); var ccaddr = new MailAddress(ccRawList[0], ccRawList[1]); message.CC.Add(ccaddr); } } //BCC's if (!string.IsNullOrEmpty(model.Bcc)) { var bccMails = model.Bcc.Split(';').ToArray(); foreach (var bccEmail in bccMails) { var bccRawList = bccEmail.Split('&'); var bccaddr = new MailAddress(bccRawList[0], bccRawList[1]); message.Bcc.Add(bccaddr); } } if (model.EmailAttachments.Count > 0) { foreach (var attachment in model.EmailAttachments) { var attachmentMetaData = new Attachment(new MemoryStream(attachment.File), attachment.FileName, MediaTypeNames.Application.Octet); message.Attachments.Add(attachmentMetaData); } } var updateEmail = _emailService.GetAll().FirstOrDefault(x => x.Id == model.Id); start2: try { smtp.Send(message); if (updateEmail == null) { return; } updateEmail.SmtpServer = smtp.Host; updateEmail.Retry = model.Retry; // WindowsSerive deneme sayısını artırıyor. updateEmail.IsSent = true; updateEmail.SentDate = DateTime.Now; updateEmail.Exception = "Last Exception was :" + model.Exception; updateEmail.LastTryDate = model.LastTryDate; _emailService.Update(updateEmail); _emailService.Save(); } catch (Exception e) { if (updateEmail != null) { updateEmail.SmtpServer = smtp.Host; updateEmail.Exception = e.InnerException == null ? e.Message : e.Message + " --> " + e.InnerException.Message; updateEmail.LastTryDate = DateTime.Now; updateEmail.Retry = model.Retry; _emailService.Update(updateEmail); _emailService.Save(); } smtp.Host = MailSmtpHost2; goto start2; } } catch (Exception ex) { #region Write Log dic = LogBusiness.GetDictionary(); dic.Add(LogFieldName.FullyQualifiedFunctionName, address); dic.Add(LogFieldName.ErrorMessage, ex.Message); dic.Add(LogFieldName.StackTrace, ex.StackTrace); LogBusiness.CustomLog(model.From, LogEvent.ErrorEvent, dic, dicParams); #endregion } finally { #region Write Log dic = LogBusiness.GetDictionary(); dic.Add(LogFieldName.FullyQualifiedFunctionName, address); dic.Add(LogFieldName.TimeElapsed, ((int)(DateTime.Now - dtEntry).TotalMilliseconds).ToString()); LogBusiness.CustomLog(model.From, LogEvent.MethodEnd, dic, dicParams); #endregion } } } } }); }
//Sends forgot password verification code to user public async Task SendForgotPasswordVerificationCodeToUserAsync(UserModel user) { if (user.Status == (int)UserStatus.NotValid) { CustomException errors = new CustomException((int)HttpStatusCode.BadRequest); errors.AddError("None Verified Email", "Your email is not verified"); errors.Throw(); } if (user.Status == (int)UserStatus.Banned) { CustomException errors = new CustomException((int)HttpStatusCode.BadRequest); errors.AddError("User Is Banned", "User is banned from application"); errors.Throw(); } string verificationCode = new Random().Next(100000, 1000000).ToString(); Task <UserInformationModel> FirstName = _userInformationRepository.GetUserInformationByIdAsync(user.Id, (await _informationRepository.GetInformationByInformationNameAsync("FirstName")).Id); Task <UserInformationModel> LastName = _userInformationRepository.GetUserInformationByIdAsync(user.Id, (await _informationRepository.GetInformationByInformationNameAsync("LastName")).Id); Task <UserInformationModel> Email = _userInformationRepository.GetUserInformationByIdAsync(user.Id, (await _informationRepository.GetInformationByInformationNameAsync("Email")).Id); InformationModel ForgotPasswordVerificationCodeInfo = await _informationRepository.GetInformationByInformationNameAsync("ForgotPasswordVerificationCode"); InformationModel ForgotPasswordVerificationCodeGenerateDateInfo = await _informationRepository.GetInformationByInformationNameAsync("ForgotPasswordVerificationCodeGenerateDate"); UserInformationModel ForgotPasswordVerificationCode = await _userInformationRepository.GetUserInformationByIdAsync(user.Id, ForgotPasswordVerificationCodeInfo.Id); UserInformationModel ForgotPasswordVerificationCodeGenerateDate = await _userInformationRepository.GetUserInformationByIdAsync(user.Id, ForgotPasswordVerificationCodeGenerateDateInfo.Id); //EMail object EMailModel mail = new EMailModel(); mail.FromName = _config["EMailConfiguration:FromName"]; mail.FromAddress = _config["EMailConfiguration:FromAddress"]; mail.ToName = (await FirstName).Value + ' ' + (await LastName).Value; mail.ToAddress = (await Email).Value; mail.Subject = "Verification Code"; mail.Content = "Your password change verification code is :" + verificationCode; Task sendMail = _mailService.SendMailAsync(mail); //First time verification code send if (ForgotPasswordVerificationCode == null) { ForgotPasswordVerificationCode = new UserInformationModel(); ForgotPasswordVerificationCode.Information = ForgotPasswordVerificationCodeInfo; ForgotPasswordVerificationCode.User = user; ForgotPasswordVerificationCode.Value = verificationCode; _userInformationRepository.Insert(ForgotPasswordVerificationCode); ForgotPasswordVerificationCodeGenerateDate = new UserInformationModel(); ForgotPasswordVerificationCodeGenerateDate.Information = ForgotPasswordVerificationCodeGenerateDateInfo; ForgotPasswordVerificationCodeGenerateDate.User = user; ForgotPasswordVerificationCodeGenerateDate.Value = String.Format("{0:u}", DateTime.UtcNow); _userInformationRepository.Insert(ForgotPasswordVerificationCodeGenerateDate); } //Not first time verification code send else { ForgotPasswordVerificationCode.Value = verificationCode; _userInformationRepository.Update(ForgotPasswordVerificationCode); ForgotPasswordVerificationCodeGenerateDate.Value = String.Format("{0:u}", DateTime.UtcNow); _userInformationRepository.Update(ForgotPasswordVerificationCodeGenerateDate); } await sendMail; }