public static void SendEmailSuccess(int UserID) { Model_Setting s = new Model_Setting(); s = s.GetSetting(); Model_Users user = GetUserbyID(UserID); string body = string.Empty; string text = File.ReadAllText(HttpContext.Current.Server.MapPath("/Theme/emailtemplate/layout_sgSuccess.html"), Encoding.UTF8); if (!string.IsNullOrEmpty(text)) { //string path = ConfigurationManager.AppSettings["AuthorizeBaseURL"].ToString().Replace("/admin", "") + "Verify?ID=" + StringUtility.EncryptedData(user.UserID.ToString()); //body = text.Replace("<!--##@Linkverfiy##-->", path); //body = text.Replace("<!--##@Linkverfiy_btn##-->", path); body = text; } MailSenderOption option = new MailSenderOption { MailSetting = s, context = HttpContext.Current, mailTo = user.Email, Mailbody = body, Subject = "การสมัครของคุณเสร็จสิ้น/ You've successfully Register to Keen Profile System" }; MAilSender.SendMailEngine(option); }
public static bool MailGunAPI(MailSenderOption option) { bool success = false; try { RestClient client = new RestClient(); //client.BaseUrl = new Uri("https://api.mailgun.net/v3/sandboxad5faabf13b54f8688be12d563b365cf.mailgun.org"); client.BaseUrl = new Uri("https://api.mailgun.net/v3"); //client.BaseUrl = new Uri("https://api.mailgun.net/v3/ns.gosolve.net"); client.Authenticator = new HttpBasicAuthenticator("api", option.MailSetting.APIKEY); RestRequest request = new RestRequest(); request.AddParameter("domain", option.MailSetting.Domain, ParameterType.UrlSegment); request.Resource = "{domain}/messages"; request.AddParameter("from", "" + option.MailSetting.MailName + " <" + option.MailSetting.MailAddress + ">"); request.AddParameter("to", "" + option.mailTo + ""); //request.AddParameter("cc", "*****@*****.**"); if (!string.IsNullOrEmpty(option.Bcc)) { request.AddParameter("bcc", "" + option.Bcc + ""); } request.AddParameter("subject", "" + option.Subject + ""); //request.AddParameter("text", "Testing some Mailgun awesomness!"); request.AddParameter("html", "" + option.Mailbody + ""); if (option.Attachment != null && option.Attachment.Count > 0) { foreach (MailSenderFileAtt attatch in option.Attachment) { string serverpath = HostingEnvironment.MapPath(attatch.Path) + attatch.FileName; request.AddFile("attachment", serverpath); //HttpContext.Current.Server.MapPath(attatch.Path + "/" + attatch.FileName) //Path.Combine(serverpath, attatch.FileName) } } //string JsonCustom = "{\"MainSite\":\"2\", \"booking_id\": \"" + booking_id + "\", \"email_sento\": \"" + mailTo + "\", \"email_type_id\": \"" + bytEmailTypeId + "\", \"email_type_title\": \"" + strEmailTitle + "\"}"; //request.AddParameter("v:my-custom-data", JsonCustom); //request.AddFile("attachment", Path.Combine("files", "test.jpg")); //request.AddFile("attachment", Path.Combine("files", "test.txt")); request.Method = Method.POST; IRestResponse ret = client.Execute(request); success = true; } catch (Exception ex) { string ee = ex.Message + ex.StackTrace; } return(success); }
public static void SendEmailReceiveToStaff(object param) { object[] parameters = (object[])param; string staffmail = (string)parameters[0]; Model_Setting s = (Model_Setting)parameters[1]; HttpContext context = (HttpContext)parameters[2]; Model_OrderPaymentTransferConfirm con = (Model_OrderPaymentTransferConfirm)parameters[3]; int intProductID = (int)parameters[4]; string body = string.Empty; string text = ""; if (intProductID == 1) { text = File.ReadAllText(context.Server.MapPath("/Theme/emailtemplate/layout_r3.html"), Encoding.UTF8); } if (intProductID == 2) { text = File.ReadAllText(context.Server.MapPath("/Theme/emailtemplate/layout_coaching.html"), Encoding.UTF8); } //if (!string.IsNullOrEmpty(text)) //{ // string path = ConfigurationManager.AppSettings["AuthorizeBaseURL"].ToString().Replace("/admin", "") + "Verify?ID=" + StringUtility.EncryptedData(user.UserID.ToString()); // body = text.Replace("<!--##@Linkverfiy##-->", "<a href=\"" + path + "\" />here</a>"); //} body = "FirstName : " + con.Name + "\r\n"; body = body + "email : " + con.Email + "\r\n"; body = body + "datetime : " + con.DatePayment.ToThaiDateTime() + "\r\n"; List <MailSenderFileAtt> list = new List <MailSenderFileAtt> { new MailSenderFileAtt { FileName = "", Path = con.FilePath } }; foreach (string email in staffmail.Split(';')) { MailSenderOption option = new MailSenderOption { MailSetting = s, context = HttpContext.Current, mailTo = email, Mailbody = body, Attachment = list, Subject = "[Keen Staff] การชำระค่าบริการเสร็จสมบูรณ์แล้ว / Success Payment Confirmation [Confirmed Order#" + con.OrderID + "]" }; MAilSender.SendMailEngine(option); } }
public static Model_Users SendEmailForgot(string email) { Model_Setting s = new Model_Setting(); s = s.GetSetting(); Model_Users user = GetUserbyEmailFront(email); if (user != null) { string body = string.Empty; string text = File.ReadAllText(HttpContext.Current.Server.MapPath("/Theme/emailtemplate/layoutforgot.html"), Encoding.UTF8); if (!string.IsNullOrEmpty(text)) { string param = user.UserID.ToString(); string time = DateTime.Now.ApiService_DateToTimestamp(); string paramstring = param + "@" + time; HttpSessionState Hotels2Session = HttpContext.Current.Session; Hotels2Session.Clear(); Hotels2Session.Timeout = 10; Hotels2Session[time] = time; string path = ConfigurationManager.AppSettings["AuthorizeBaseURL"].ToString().Replace("/admin", "") + "ResetPassword?e=" + StringUtility.EncryptedData(paramstring); body = text.Replace("<!--##@Linkresetpassword##-->", path); } MailSenderOption option = new MailSenderOption { MailSetting = s, context = HttpContext.Current, mailTo = user.Email, Mailbody = body, Subject = "Forgot password and reset password" }; MAilSender.SendMailEngine(option); } return(user); }
//private static string _maildisplayBooking = "*****@*****.**"; //byte sendserverType , string maildisplay, string mailNamedisplay, string mailTo, string Subject, string Bcc, string Mailbody, IDictionary<string, string> idicAttachment = null public static bool SendMailEngine(MailSenderOption option) { bool ret = false; switch (option.MailSetting.ST) { case 1: ret = SendMailSMTP(option); break; case 2: ret = MailGunAPI(option); break; } return(ret); }
public static void SendEmaiReceiveToCustomer(object param) { object[] parameters = (object[])param; Model_Users user = (Model_Users)parameters[0]; Model_Setting s = (Model_Setting)parameters[1]; HttpContext context = (HttpContext)parameters[2]; int intProductID = (int)parameters[3]; string body = string.Empty; string text = string.Empty; if (intProductID == 1) { text = File.ReadAllText(context.Server.MapPath("/Theme/emailtemplate/layout_r3.html"), Encoding.UTF8); } if (intProductID == 2) { text = File.ReadAllText(context.Server.MapPath("/Theme/emailtemplate/layout_coaching.html"), Encoding.UTF8); } //if (!string.IsNullOrEmpty(text)) //{ // string path = ConfigurationManager.AppSettings["AuthorizeBaseURL"].ToString().Replace("/admin", "") + "Verify?ID=" + StringUtility.EncryptedData(user.UserID.ToString()); // body = text.Replace("<!--##@Linkverfiy##-->", "<a href=\"" + path + "\" />here</a>"); //} body = text; MailSenderOption option = new MailSenderOption { MailSetting = s, context = HttpContext.Current, mailTo = user.Email, Mailbody = body, Subject = "การชำระค่าบริการเสร็จสมบูรณ์แล้ว / Success Payment Confirmation" }; MAilSender.SendMailEngine(option); }
public static bool SendMailSMTP(MailSenderOption option) { bool success = false; try { MailMessage mail = new MailMessage(); mail.From = new MailAddress(option.MailSetting.MailAddress, option.MailSetting.MailName); if (!string.IsNullOrEmpty(option.Bcc)) { mail.Bcc.Add(option.Bcc); } mail.To.Add(option.mailTo); mail.Subject = option.Subject.Trim(); mail.Body = option.Mailbody; mail.IsBodyHtml = true; //string strCustomVariable = ""; //foreach (var item in dicCustomVariable) //{ // strCustomVariable += ",\"" + item.Key + "\":\"" + item.Value + "\""; //} //strCustomVariable = strCustomVariable.RemoveBeginOrEnd(","); //if (strCustomVariable != "") mail.Headers.Add("X-Mailgun-Variables", "{" + strCustomVariable + "}"); //Extend function by darkman 20-08-2016 if (option.Attachment != null && option.Attachment.Count > 0) { foreach (MailSenderFileAtt attatch in option.Attachment) { string ss = HostingEnvironment.MapPath(attatch.Path + attatch.FileName); System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(ss); mail.Attachments.Add(attachment); } } /// System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient(); smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; smtpClient.EnableSsl = option.MailSetting.IsSSL; smtpClient.Port = option.MailSetting.Port; smtpClient.Host = option.MailSetting.MailServer.Trim(); smtpClient.Credentials = new System.Net.NetworkCredential(option.MailSetting.MailServerUser.Trim(), option.MailSetting.MailServerPass.Trim());//"bluehousetravel","vug,]NFVgm]m^wmpc]ofN" smtpClient.Send(mail); success = true; } catch (Exception ex) { //(Exception ex) } return(success); }
public static void SendEmailReceiveToStaff() { Model_Setting s2 = new Model_Setting(); s2 = s2.GetSetting(); int intProductID = 1; string staffEmail = "[email protected];[email protected]"; object[] param = new object[] { staffEmail, s2 }; object[] parameters = (object[])param; string staffmail = (string)parameters[0]; Model_Setting s = (Model_Setting)parameters[1]; HttpContext context = HttpContext.Current; //Model_OrderPaymentTransferConfirm con = (Model_OrderPaymentTransferConfirm)parameters[3]; string body = string.Empty; string text = ""; if (intProductID == 1) { text = File.ReadAllText(context.Server.MapPath("/Theme/emailtemplate/layout_r3.html"), Encoding.UTF8); } if (intProductID == 2) { text = File.ReadAllText(context.Server.MapPath("/Theme/emailtemplate/layout_coaching.html"), Encoding.UTF8); } //if (!string.IsNullOrEmpty(text)) //{ // string path = ConfigurationManager.AppSettings["AuthorizeBaseURL"].ToString().Replace("/admin", "") + "Verify?ID=" + StringUtility.EncryptedData(user.UserID.ToString()); // body = text.Replace("<!--##@Linkverfiy##-->", "<a href=\"" + path + "\" />here</a>"); //} body = "FirstName : tet\r\n"; body = body + "email : tet\r\n"; body = body + "datetime : sss\r\n"; FileInfo file = new FileInfo(HttpContext.Current.Server.MapPath("/orderconfirmfile/10033.jpg")); List <MailSenderFileAtt> list = new List <MailSenderFileAtt>(); if (file.Exists) { list.Add(new MailSenderFileAtt { FileName = "", Path = "/orderconfirmfile/10033.jpg" }); } foreach (string email in staffmail.Split(';')) { MailSenderOption option = new MailSenderOption { MailSetting = s, context = HttpContext.Current, mailTo = email, Mailbody = body, Attachment = list, Subject = "[Keen Staff] การชำระค่าบริการเสร็จสมบูรณ์แล้ว / Success Payment Confirmation " }; MAilSender.SendMailEngine(option); } }
public static void Sendnow(object param) { object[] parameters = (object[])param; List <Model_SendingJobItem> cli = (List <Model_SendingJobItem>)parameters[0]; Model_Setting s = (Model_Setting)parameters[1]; Model_SendingJob ms = (Model_SendingJob)parameters[2]; HttpContext context = (HttpContext)parameters[3]; //Model_SendingJob ms = new Model_SendingJob(); //var groupCampaignCID = cli.Where(cam => cam.CType == 1).GroupBy(c => c.CID); //var groupMailboxCID = cli.Where(cam => cam.CType == 2).GroupBy(c => c.CID); //StringBuilder strCam = new StringBuilder(); //StringBuilder strMailBox = new StringBuilder(); //foreach (var ss in groupCampaignCID) //{ // int propertyIntOfClassA = ss.Key; // strCam.Append(propertyIntOfClassA + ","); //} //strCam.Append("0"); //foreach (var ss in groupMailboxCID) //{ // int propertyIntOfClassA = ss.Key; // strMailBox.Append(propertyIntOfClassA + ","); //} //strMailBox.Append("0"); IList <Model_Campaign> mdc = CampaignController.GetCampaign(ms.CID.ToString()); IList <Model_Mailbox> mdm = MailboxController.GetMailbox(ms.CID.ToString()); MailSenderOption option = new MailSenderOption { MailSetting = s, context = context }; EmailEelements e = new EmailEelements(); // _el = (EModel)e.model_GetElementBYID(this.EID).Eelement.JsonToObject(new EModel()); int count = 1; foreach (Model_SendingJobItem c in cli) { if (c.CType == 1) { Model_Campaign cam = mdc.SingleOrDefault(r => r.CID == c.CID); EModel el = (EModel)cam.ELRaw.JsonToObject(new EModel()); option.Subject = cam.Subject; string bodymail = el.html; if (cam.Unsub) { bodymail = bodymail.Replace("</body>", appendSubscription(c.SID)); } option.Mailbody = bodymail; if (!string.IsNullOrEmpty(cam.FileMail)) { option.Attachment = GetFileMail(cam.FileMail); } } else { Model_Mailbox cam = mdm.SingleOrDefault(r => r.CID == c.CID); EModel el = (EModel)cam.ELRaw.JsonToObject(new EModel()); option.Subject = cam.Subject; string bodymail = appendHtmlforMailbox(el.html); if (cam.Unsub && c.SID != 0) { bodymail = bodymail.Replace("</body>", appendSubscription(c.SID)); } option.Mailbody = bodymail; if (!string.IsNullOrEmpty(cam.FileMail)) { option.Attachment = GetFileMail(cam.FileMail); } } option.mailTo = c.Email; //"*****@*****.**", "Gosolve", c.Email, "Thread Sending", "", "Thread Sending Thread Sending" if (MAilSender.SendMailEngine(option)) { c.UpdateStatus(c.SDIID, true); } // Lock.AcquireWriterLock(Timeout.Infinite); //SendingEngineController.SendResponse.SingleOrDefault(ii => ii.CID == c.CID).TotalSent += 1; // Lock.ReleaseWriterLock(); ms.UpdateTotalSentAndISDone(c.SDID); count = count + 1; } Lock.AcquireWriterLock(Timeout.Infinite); SendingEngineController.Onprocess = false; Lock.ReleaseWriterLock(); }