public IHttpActionResult EmailReceipt(plot plotObj) { string senderEmail = string.Empty; try { var customer = service.GetCustomerByPlotId(plotObj.Id); if (customer == null) { return(Ok("Customer not found!")); } byte[] buffer = GetTemplate(plotObj); string paymentReceipt = Path.Combine(Path.GetTempPath(), plotObj.DocumentType + ".pdf"); File.WriteAllBytes(paymentReceipt, buffer); senderEmail = customer.Email; MailSettingViewModel settings = new MailSettingViewModel { Subject = "Document", Body = "Dear Sir/Madam<br><br><br>Your property document attached with this email. <br> Please find attachment.<br><br>Thank you.", ToMailId = customer.Email, ToMailName = customer.CustomerName }; settings.AttchPath.Add(paymentReceipt); services.Common.EmailService.SendMail(settings); return(Ok("Email sent successfully on '" + senderEmail + "' email id")); } catch (Exception ex) { return(Ok("Error occurred while in sending mail to " + senderEmail + Environment.NewLine + " Error Details:" + ex.ToString())); } }
public IActionResult Update(SiteSettingViewModel siteSetting, MailSettingViewModel mailSetting, SSOSettingViewModel SSOSetting) { var currentSiteSetting = _siteSettingRepository.Single(); var currentMailSetting = _mailSettingRepository.Single(); var currentSsoSetting = _ssoSettingRepository.Single(); if (currentSiteSetting == null) { currentSiteSetting = new Domain.Application.Entities.SiteSetting() { Id = Guid.NewGuid().ToString() }; _siteSettingRepository.Add(currentSiteSetting); } else { _siteSettingRepository.Update(currentSiteSetting); } if (currentMailSetting == null) { currentMailSetting = new Domain.Application.Entities.MailSetting() { Id = Guid.NewGuid().ToString() }; _mailSettingRepository.Add(currentMailSetting); } else { _mailSettingRepository.Update(currentMailSetting); } if (currentSsoSetting == null) { currentSsoSetting = new Domain.Application.Entities.SSOSetting() { Id = Guid.NewGuid().ToString() }; _ssoSettingRepository.Add(currentSsoSetting); } else { _ssoSettingRepository.Update(currentSsoSetting); } PropertyCopy.Copy(siteSetting, currentSiteSetting); PropertyCopy.Copy(mailSetting, currentMailSetting); PropertyCopy.Copy(SSOSetting, currentSsoSetting); _siteSettingRepository.Save(RequestContext); _configuration.SetConfiguration(); return(RedirectToAction("Index")); }
public IActionResult Update(SiteSettingViewModel siteSetting, MailSettingViewModel mailSetting, SSOSettingViewModel SSOSetting) { var CurrentSiteSetting = siteSettingRepository.Single(); var CurrentMailSetting = mailSettingRepository.Single(); var CurrentSSOSetting = SSOSettingRepository.Single(); if (CurrentSiteSetting == null) { CurrentSiteSetting = new Domain.Application.Entities.SiteSetting() { Id = Guid.NewGuid().ToString() }; siteSettingRepository.Add(CurrentSiteSetting); } else { siteSettingRepository.Update(CurrentSiteSetting); } if (CurrentMailSetting == null) { CurrentMailSetting = new Domain.Application.Entities.MailSetting() { Id = Guid.NewGuid().ToString() }; mailSettingRepository.Add(CurrentMailSetting); } else { mailSettingRepository.Update(CurrentMailSetting); } if (CurrentSSOSetting == null) { CurrentSSOSetting = new Domain.Application.Entities.SSOSetting() { Id = Guid.NewGuid().ToString() }; SSOSettingRepository.Add(CurrentSSOSetting); } else { SSOSettingRepository.Update(CurrentSSOSetting); } PropertyCopy.Copy(siteSetting, CurrentSiteSetting); PropertyCopy.Copy(mailSetting, CurrentMailSetting); PropertyCopy.Copy(SSOSetting, CurrentSSOSetting); siteSettingRepository.Save(requestContext); configuration.SetConfiguration(); return(RedirectToAction("Index")); }
public static void SendMail(MailSettingViewModel settings) { var smtpSection = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp"); var fromAddress = new MailAddress(smtpSection.Network.UserName, smtpSection.Network.UserName); var toAddress = new MailAddress(settings.ToMailId, settings.ToMailName); string fromPassword = smtpSection.Network.Password; var smtp = new SmtpClient { Host = smtpSection.Network.Host, Port = smtpSection.Network.Port, EnableSsl = smtpSection.Network.EnableSsl, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(fromAddress.Address, fromPassword) }; using (var message = new MailMessage(fromAddress, toAddress) { Subject = settings.Subject, Body = settings.Body, IsBodyHtml = true }) { if (settings.AttchPath != null && settings.AttchPath.Count > 0) { foreach (var filepath in settings.AttchPath) { System.Net.Mail.Attachment attachment; attachment = new System.Net.Mail.Attachment(filepath); message.Attachments.Add(attachment); } } smtp.Send(message); } }
public IHttpActionResult EmailReceipt(payment paymentobj) { string senderEmail = string.Empty; try { var customer = service.GetCustomerByPlotId(paymentobj.Id); if (customer == null) { return(Ok("Customer not found!")); } var result = service.DownloadReceipt(paymentobj); var example_html = "<html><body>" + result + "</body></html>"; byte[] buffer = GetTemplate(paymentobj, example_html); string paymentReceipt = Path.Combine(Path.GetTempPath(), "payment_receipt.pdf"); File.WriteAllBytes(paymentReceipt, buffer); senderEmail = customer.Email; MailSettingViewModel settings = new MailSettingViewModel { Subject = "Payment Receipt", Body = example_html, ToMailId = customer.Email, ToMailName = customer.CustomerName }; settings.AttchPath.Add(paymentReceipt); services.Common.EmailService.SendMail(settings); return(Ok("Email sent successfully on '" + senderEmail + "' email id")); } catch (Exception ex) { return(Ok("Error occurred while in sending mail to " + senderEmail + Environment.NewLine + " Error Details:" + ex.ToString())); } }
public SendMailService(IOptions <MailSettingViewModel> mailSettings, ILogger <SendMailService> logger) { this.mailSettings = mailSettings.Value; this.logger = logger; logger.LogInformation("Create SendMailService"); }
public void SendEmail(string content, string ToEmail, string subject, string Title, MailSettingViewModel mailSetting) { try { using (MailMessage mail = new MailMessage()) { mail.From = new MailAddress(mailSetting.SmtpUsername); mail.To.Add(ToEmail); mail.Subject = subject; mail.Body = Title + content; using (SmtpClient smtp = new SmtpClient(mailSetting.SmtpServer, mailSetting.SmtpPort.Value)) { smtp.Credentials = new NetworkCredential(mailSetting.SmtpUsername, mailSetting.SmtpPassword); smtp.EnableSsl = true; smtp.Send(mail); } } } catch (Exception e) { throw e; } }