private List <SendEmailInfo> Get_Thank_You_Email(List <MemberEventInfo> eventmembers) { List <SendEmailInfo> sendEmails = new List <SendEmailInfo>(); foreach (var item in eventmembers) { SendEmailInfo emailData = new SendEmailInfo(); emailData.ID = item.Member_Event_Mapping_Id; emailData.To_Email_Id = item.Email; emailData.Subject = "Thank you Email"; StringBuilder htmlString = new StringBuilder(); htmlString.Append("<p>"); htmlString.Append("Hi " + item.Member_Name); htmlString.Append("</p>"); htmlString.Append("<p>"); htmlString.Append("Thank you for attending event " + item.Event_Name + "."); htmlString.Append("</p>"); htmlString.Append("<br />"); htmlString.Append("<p>"); htmlString.Append("<b>Regards :</b> "); htmlString.Append("</p>"); emailData.Body = htmlString.ToString(); sendEmails.Add(emailData); } return(sendEmails); }
private List <SendEmailInfo> Get_Customer_Registration_Email(List <CustomerInfo> customers) { List <SendEmailInfo> sendEmails = new List <SendEmailInfo>(); foreach (var item in customers) { SendEmailInfo emailData = new SendEmailInfo(); emailData.ID = item.Customer_Id; emailData.To_Email_Id = item.Email; emailData.Subject = "Welcome Email"; StringBuilder htmlString = new StringBuilder(); htmlString.Append("<p>"); htmlString.Append("Hi " + item.Customer_Name); htmlString.Append("</p>"); htmlString.Append("<p>"); htmlString.Append("You are succefully registered at MagniPi."); htmlString.Append("</p>"); htmlString.Append("<br />"); htmlString.Append("<p>"); htmlString.Append("<b>Regards :</b> "); htmlString.Append("</p>"); emailData.Body = htmlString.ToString(); sendEmails.Add(emailData); } return(sendEmails); }
public static void SendMail(SendEmailInfo sendEmail) { MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient(); if (!string.IsNullOrEmpty(sendEmail.To_Email_Id)) { if (sendEmail.To_Email_Id.Contains(',')) { foreach (var item in sendEmail.To_Email_Id.Split(',')) { mail.To.Add(item); } } else { mail.To.Add(sendEmail.To_Email_Id); } } if (!string.IsNullOrEmpty(sendEmail.CC_Email_Id)) { if (sendEmail.CC_Email_Id.Contains(',')) { foreach (var item in sendEmail.CC_Email_Id.Split(',')) { mail.CC.Add(item); } } else { mail.CC.Add(sendEmail.CC_Email_Id); } } mail.Subject = sendEmail.Subject; mail.Body = sendEmail.Body; mail.IsBodyHtml = true; SmtpServer.Send(mail); }
public void SendEmail(VM.UserInfoItem model, string password, string emailTemplateName) { bool isSendEmailtoIIS = false; var sendEmailInfo = new SendEmailInfo(); var email = Ctx.tbl_EmailTemplate.FirstOrDefault(t => t.Name == emailTemplateName); string[] emailSendTo = { model.EmailAddress }; string url = string.Format("{0}/", EmailTemplateParam.GetHostName()); sendEmailInfo.mailSubject = email.EmailSubject.Replace(EmailTemplateParam.SystemName, EmailTemplateParam.SystemNameBasic); sendEmailInfo.mailBody = email.EmailContent.Replace(EmailTemplateParam.UserDisplayName, model.LogonName) .Replace(EmailTemplateParam.URL, url) .Replace(EmailTemplateParam.UserName, model.LogonName) .Replace(EmailTemplateParam.Password, password) .Replace("[DateTime]", DateTime.Now.ToString("yyyy年MM月dd日")); //MailHelper.SendMail(emailSendTo, sendEmailInfo.mailSubject, sendEmailInfo.mailBody, 0, isSendEmailtoIIS, true); }
private List <SendEmailInfo> Get_Reminder_Email(List <MemberEventInfo> eventmembers) { List <SendEmailInfo> sendEmails = new List <SendEmailInfo>(); foreach (var item in eventmembers) { SendEmailInfo emailData = new SendEmailInfo(); emailData.ID = item.Member_Event_Mapping_Id; emailData.To_Email_Id = item.Email; emailData.Subject = "Reminder Email"; StringBuilder htmlString = new StringBuilder(); htmlString.Append("<p>"); htmlString.Append("Hi " + item.Member_Name); htmlString.Append("</p>"); htmlString.Append("<p>"); htmlString.Append("Thank you for registering the <b>" + item.Event_Name + "</b> ."); htmlString.Append("We are going to conducting this " + item.Event_Type_Str + " on tomorrow<b> at " + item.Location + " ."); htmlString.Append("</p>"); htmlString.Append("<p>"); htmlString.Append("<b>About Event :</b> " + item.Description); htmlString.Append("</p>"); htmlString.Append("<br />"); htmlString.Append("<p>"); htmlString.Append("<b>Regards :</b> "); htmlString.Append("</p>"); emailData.Body = htmlString.ToString(); sendEmails.Add(emailData); } return(sendEmails); }
public ActionResult SendEmail(SendEmailInfoViewModel viewModel) { try { if (ModelState.IsValid) { var sendEmailInfo = new SendEmailInfo { SenderName = viewModel.SenderName, SenderContactNo = viewModel.SenderContactNo, Subject = viewModel.Subject, Message = viewModel.Message, MemberId = viewModel.MemberViewModelId }; var member = _db.Members.Find(viewModel.MemberViewModelId); var user = _db.Users.Find(member.UserName); var toEmail = user != null ? user.Email : null; var body = viewModel.Message + "Contact No: " + viewModel.SenderContactNo; SendMailHelper sendMailHelper = new SendMailHelper(); bool isResult = sendMailHelper.SendEmail(toEmail, viewModel.Subject, body); if (isResult) { _db.SendEmailInfos.Add(sendEmailInfo); _db.SaveChanges(); return(Content(Boolean.TrueString)); } else { return(Content("Sorry! Unable to send email to this member.")); } } return(Content(ExceptionHelper.ModelStateErrorFormat(ModelState))); } catch (Exception ex) { ExceptionHelper.ExceptionMessageFormat(ex, true); return(Content("Sorry! Unable to send email to this member.")); } }
public genericResponse Save(SendEmailInfo emailInfo) { genericResponse _response; try { #region [[ Basic Check Here...]] if (emailInfo != null && !string.IsNullOrEmpty(emailInfo.SUBJECT) && !string.IsNullOrEmpty(emailInfo.MESSAGE) //To Address Option.... && (!string.IsNullOrEmpty(emailInfo.RCPNTS) || CheckRecipientsExist(emailInfo.userEmailGroups) || CheckRecipientsExist(emailInfo.blastEmailGroups))) { #region [[ Continue as we are good...]] bool IsMessageSent = false; string _file_path = ""; var sendEmails = Convert.ToBoolean(ConfigurationManager.AppSettings["General.SendBlastEmails"]); //Let us gather Information for sending Email out... var client = new SmtpClient(); if (Convert.ToBoolean(ConfigurationManager.AppSettings["Server.UseDefaultCredentials"].ToString())) client.UseDefaultCredentials = true; client.Host = ConfigurationManager.AppSettings["Server.Hostname"].ToString();// "smtp.cso.local"; client.Port = int.Parse(ConfigurationManager.AppSettings["Server.Port"].ToString());//25; //client.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis; if (Convert.ToBoolean(ConfigurationManager.AppSettings["Server.CredentialsRequired"].ToString())) client.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["Server.Username"].ToString(), ConfigurationManager.AppSettings["Server.Password"].ToString()); //Now set up MailMessage MailMessage message = new MailMessage(); message.IsBodyHtml = true; //From Address if (Convert.ToBoolean(ConfigurationManager.AppSettings["Server.CredentialsRequired"].ToString())) { message.From = new MailAddress("*****@*****.**"); } else { message.From = new MailAddress(CurrentUser.EmailAdress); } //Subject message.Subject = emailInfo.SUBJECT.Trim(); message.Body = emailInfo.MESSAGE.Trim().Replace("\r\n", "<br/>").Replace(" ", " "); //Set To Address as From by default message.To.Add(message.From); //For Entered Email Addresses if (!string.IsNullOrEmpty(emailInfo.RCPNTS)) { //We also have email address entered here string[] receiverAddress = emailInfo.RCPNTS.Trim().Split(','); foreach (string address in receiverAddress) { //Add Address as To if (Validation.ValidateEmail(address.Trim())) { message.To.Add(new MailAddress(address.Trim())); } } } //For Blast Email Groups.... foreach (EmailGroups beg in emailInfo.blastEmailGroups) { if (beg.IsSelected) { //This group is selected so let us get Email Addresses and add them as BCC switch (beg.name) { case "All Coach": emailAdrsInfo = uow.EmailRepository().GetAllCoachAddresses().ToList(); message = AddAddresses(emailAdrsInfo, message); break; case "All Franchisee Owners": emailAdrsInfo = null; emailAdrsInfo = uow.EmailRepository().GetAllFranchiseeAddresses("FranchiseeOwner").ToList(); message = AddAddresses(emailAdrsInfo, message); break; case "Franchisee Owner": emailAdrsInfo = null; emailAdrsInfo = uow.EmailRepository().GetFranchiseeAddresses("FranchiseeOwner", CurrentUser.FranchiseeID).ToList(); message = AddAddresses(emailAdrsInfo, message); break; case "All Franchisee Users": emailAdrsInfo = null; emailAdrsInfo = uow.EmailRepository().GetAllFranchiseeAddresses("FranchiseeUser").ToList(); message = AddAddresses(emailAdrsInfo, message); break; case "Franchisee Users": emailAdrsInfo = null; emailAdrsInfo = uow.EmailRepository().GetFranchiseeAddresses("FranchiseeUser", CurrentUser.FranchiseeID).ToList(); message = AddAddresses(emailAdrsInfo, message); break; case "All Franchisee Contacts": case "Franchisee Contacts": int FrId; emailAdrsInfo = null; if ((CurrentUser.Role == SandlerRoles.Corporate) || (CurrentUser.Role == SandlerRoles.SiteAdmin)) { FrId = 0; } else { FrId = CurrentUser.FranchiseeID; } emailAdrsInfo = uow.EmailRepository().GetAllContactsAddresses(FrId).ToList(); message = AddAddresses(emailAdrsInfo, message); break; default: break; } } } //For User Grooup if any selected ..... foreach (EmailGroups usrg in emailInfo.userEmailGroups) { if (usrg.IsSelected) { emailAdrsInfo = null; emailAdrsInfo = uow.EmailRepository().GetUserEmailGroupAddresses(Convert.ToInt32(usrg.Id)).ToList(); message = AddAddresses(emailAdrsInfo, message); } } //For Attachement... if (!string.IsNullOrEmpty(emailInfo.FILENAMES)) { //Now save the file in the tmp folder _file_path = System.Web.Hosting.HostingEnvironment.MapPath("~"); if (_file_path.Substring(_file_path.Length) != "\\") { _file_path += "\\"; } _file_path += "Uploads\\" + emailInfo.FILENAMES; using (System.IO.FileStream fileStream = new System.IO.FileStream(_file_path, System.IO.FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { System.Net.Mail.Attachment _attachment = new System.Net.Mail.Attachment(fileStream, emailInfo.FILENAME, MediaTypeNames.Application.Octet); // Add time stamp information for the file. ContentDisposition disposition = _attachment.ContentDisposition; disposition.CreationDate = System.IO.File.GetCreationTime(_file_path); disposition.ModificationDate = System.IO.File.GetLastWriteTime(_file_path); disposition.ReadDate = System.IO.File.GetLastAccessTime(_file_path); // Add the file attachment to this e-mail message. message.Attachments.Add(_attachment); //Send the message with Attachment if (sendEmails) { client.Timeout = 30000000; client.Send(message); IsMessageSent = true; } } //Now delete attachment File.Delete(_file_path); } //Send the message for non-Attachment Messages... if (sendEmails && !IsMessageSent) { client.Timeout = 30000000; client.Send(message); } _response = new genericResponse() { success = true }; #endregion } else { _response = new genericResponse() { success = false, message = "Recipient is missing. Either enter email address or select group from the list to proceed." }; } #endregion //Back return _response; } catch (Exception ex) { _response = new genericResponse() { success = false, message = "There is a problem in sending the Email message. Please try again later. " + ex.Message }; return _response; } }