public ResponseModel SendMessae(Message aObj) { try { // var x = AuditLog.GetAuditLog(); if (aObj.Name == null) { return(_aModel.Respons(false, "Name is required.")); } if (aObj.Subject == null) { return(_aModel.Respons(false, "Subject is required.")); } if (aObj.Email == null) { return(_aModel.Respons(false, "Email is required.")); } if (aObj.MessageDetails == null) { return(_aModel.Respons(false, "Message is required.")); } Regex regex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$"); Match match = regex.Match(aObj.Email); if (!match.Success) { return(_aModel.Respons(false, "Please enter valid Email address.")); } aObj.CreateDate = DateTime.Now; aObj.IsRead = false; if (aObj.MessageId != 0) { _aRepository.Update(aObj); } else { _aRepository.Insert(aObj); } _aRepository.Save(); SendEmail(aObj); return(_aModel.Respons(true, "Data Successfully Saved")); } catch (Exception ex) { IGenericRepository <Audit> _auditRepository = new GenericRepositoryCms <Audit>(); Audit _audit = new Audit() { Message = ex.Message.ToString() + "-" + ex.InnerException, IsAdmin = true }; _auditRepository.Insert(_audit); _auditRepository.Save(); return(_aModel.Respons(false, "Sorry! There is some ERROR. " + ex.Message)); } }
public void SendEmail(Message aObj) { try { //SmtpClient smtpClient = new SmtpClient("mail.MyWebsiteDomainName.com", 25); //smtpClient.Credentials = new System.Net.NetworkCredential("*****@*****.**", "myIDPassword"); //smtpClient.UseDefaultCredentials = true; //smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; //smtpClient.EnableSsl = true; //MailMessage mail = new MailMessage(); ////Setting From , To and CC //mail.From = new MailAddress("info@MyWebsiteDomainName", "MyWeb Site"); //mail.To.Add(new MailAddress("info@MyWebsiteDomainName")); //mail.CC.Add(new MailAddress("*****@*****.**")); //smtpClient.Send(mail); var systemSettings = _aSystemSettingRepository.SelectAll().FirstOrDefault(); var fromAddress = new MailAddress("*****@*****.**", "Nafiz Imtiaz Rifat"); var toAddress = new MailAddress(aObj.Email, aObj.Name); const string fromPassword = "******"; const string subject = "Thank You From nafizrifat.com"; string body = systemSettings.EmailContent; body = body.Replace("{0}", aObj.Name); body = body.Replace("{1}", aObj.Ip); body = body.Replace("{2}", aObj.PcName); var smtp = new SmtpClient { //Host = "smtp.gmail.com", Host = "relay-hosting.secureserver.net", // Host = "smtpout.secureserver.net", //Port = 587, Port = 25, EnableSsl = false, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(fromAddress.Address, fromPassword) }; using (var message = new MailMessage(fromAddress, toAddress) { Subject = subject, Body = body }) { message.IsBodyHtml = true; smtp.Send(message); } //Audit _audit = new Audit() //{ // Message = "message sent", // IsAdmin = true //}; //_auditRepository.Insert(_audit); //_auditRepository.Save(); } catch (Exception ex) { IGenericRepository <Audit> _auditRepository = new GenericRepositoryCms <Audit>(); Audit _audit = new Audit() { // Message = ex.Message.ToString() + "-" + ex.InnerException, Message = ex.Message.ToString(), IsAdmin = true, AuditTime = DateTime.Now }; _auditRepository.Insert(_audit); _auditRepository.Save(); return; } }