public static string SendEmailToGroup(string body, string subject, string group, string attachment = "") { SmtpClient client = new SmtpClient(); string strMessage = string.Empty; MailMessage msg = new MailMessage(); // Populate the SmtpClient and MailMessage with the setting in the Web.config GetMailSettings(client, msg); // get selected group emails EmailGroupsBL bl = new EmailGroupsBL(); foreach (var item in bl.GetEmailReceiver(group)) { msg.To.Add(new MailAddress(item.Name)); } msg.Subject = subject; msg.IsBodyHtml = true; msg.Body = body; if (!string.IsNullOrEmpty(attachment)) { msg.Attachments.Add(new Attachment(attachment)); } try { client.Send(msg); return strMessage; } catch (Exception ex) { //throw ex; return ex.Message; } }
public static void SendEmailToSelectedGroup(string body, string subject, string attachment = "") { SmtpClient client = new SmtpClient(); MailMessage msg = new MailMessage(); // Populate the SmtpClient and MailMessage with the setting in the Web.config GetMailSettings(client, msg); // get selected group emails EmailGroupsBL bl = new EmailGroupsBL(); foreach (var item in bl.GetEmailReceiver()) { msg.To.Add(new MailAddress(item.Name)); } msg.Subject = subject; msg.IsBodyHtml = true; msg.Body = body; if (!string.IsNullOrEmpty(attachment)) { msg.Attachments.Add(new Attachment(attachment)); } EmailQueBL queBl = new EmailQueBL(); tblEmailQue que = new tblEmailQue(); que.Name = subject; que.SendTime = DateTime.Now; que.IsSent = false; try { if (!queBl.IsTodayEmailSent()) { client.Send(msg); que.IsSent = true; } } catch (Exception ex) { //throw ex; } finally { queBl.AddEmailQue(que); } }
private void BindEmails() { EmailGroupsBL bl = new EmailGroupsBL(); grdEmail.DataSource = bl.GetAll().OrderBy(c => c.GroupName).ToList(); grdEmail.DataBind(); }
protected void btnSaveEmail_Click(object sender, EventArgs e) { EmailGroup model = new EmailGroup(); if (!string.IsNullOrEmpty(hfEmailGroupId.Value)) { model.ID = Convert.ToInt32(hfEmailGroupId.Value); LogActivity("Email Updated", "Email has been updated", string.Empty); } else { LogActivity("Email Created", "Email has been created", string.Empty); } model.GroupName = ddlGroups.SelectedItem.Text; model.Name = txtEmail.Text; EmailGroupsBL bl = new EmailGroupsBL(); bl.Save(model); BindEmails(); hfEmailGroupId.Value = string.Empty; }
protected void grdEmail_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e) { EmailGroupsBL bll = new EmailGroupsBL(); if (e.CommandName == "Remove") { int id = Convert.ToInt32(e.CommandArgument); bll.Delete(id); BindEmails(); LogActivity("Email Removed", "Email has been removed", string.Empty); } else if (e.CommandName == "EditRow") { int id = Convert.ToInt32(e.CommandArgument); EmailGroup model = bll.GetById(id); txtEmail.Text = model.Name; ddlGroups.ClearSelection(); // ddlGroups.FindItemByText(model.GroupName).Selected = true; ddlGroups.Items.FindByText(model.GroupName).Selected = true; hfEmailGroupId.Value = model.ID.ToString(); } else if (e.CommandName == "SendEmail") { string str = ReportHelper.GenerateAndSendPDFReport(e.CommandArgument.ToString()); if (str != string.Empty) { lblEmailError.Visible = true; lblEmailError.InnerText = str; } ShowMessage("Message", "Emails has been set to all the addresses in the group(" + e.CommandArgument.ToString() + ")"); } BindEmails(); }