public void AddEmailQue(tblEmailQue model) { using (LoanPriceEntities context = new LoanPriceEntities()) { tblEmailQue que = context.tblEmailQues.FirstOrDefault(c => EntityFunctions.TruncateTime(c.SendTime) == EntityFunctions.TruncateTime(model.SendTime)); if (que == null) { context.tblEmailQues.AddObject(model); context.SaveChanges(); } } }
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); } }
/// <summary> /// Create a new tblEmailQue object. /// </summary> /// <param name="id">Initial value of the ID property.</param> /// <param name="sendTime">Initial value of the SendTime property.</param> /// <param name="isSent">Initial value of the IsSent property.</param> public static tblEmailQue CreatetblEmailQue(global::System.Int32 id, global::System.DateTime sendTime, global::System.Boolean isSent) { tblEmailQue tblEmailQue = new tblEmailQue(); tblEmailQue.ID = id; tblEmailQue.SendTime = sendTime; tblEmailQue.IsSent = isSent; return tblEmailQue; }
/// <summary> /// Deprecated Method for adding a new object to the tblEmailQues EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddTotblEmailQues(tblEmailQue tblEmailQue) { base.AddObject("tblEmailQues", tblEmailQue); }