public int ExecuteDML(string strSQL, CommandType cmdType, int intTimeout) { int status = 0; SqlConnection conn = new SqlConnection(strConnString); try { cmd.CommandText = strSQL; cmd.CommandType = cmdType; cmd.CommandTimeout = intTimeout; conn.Open(); cmd.Connection = conn; status = cmd.ExecuteNonQuery(); cmd.Parameters.Clear(); } catch (System.Exception ex) { status = -1; try { logger.log("error", strSQL, ex.Message); } catch (System.Exception) { } } finally { cmd.Cancel(); conn.Close(); conn.Dispose(); } return(status); }
public string send_sms(string mobile_no, string text, string tag) { bool success = false; string sms_gateway_response = ""; string fetch_url = ""; string[] mobile_nos = mobile_no.Split(','); foreach (string mobile in mobile_nos) { try { success = false; fetch_url = this.gateway_url; fetch_url = fetch_url.Replace("@@mobile_no", mobile); fetch_url = fetch_url.Replace("@@sms_text", text); fetch_url = fetch_url.Replace("@@senderid", tag); Utils.HTTP sms_http = new Utils.HTTP(); sms_gateway_response = sms_http.GET(fetch_url); success = sms_gateway_response.ToUpper().Contains("3001"); if (!success) { success = sms_gateway_response.ToUpper().Contains("SENT"); } } catch (System.Exception ex) { logger.log("error", ex); } if (!success) { this.logger.log("fatal", sms_gateway_response); throw new System.Exception("Failed to send sms"); } } return(fetch_url); }
//sends the message. public bool send_email(int booking_id, string to_email_ids, string cc_email_ids, string bcc_email_ids) { Utils.clsLogger logger = new Utils.clsLogger(); if (to_email_ids == null) to_email_ids = ""; if (cc_email_ids == null) cc_email_ids = ""; if (bcc_email_ids == null) bcc_email_ids = ""; MailMessage message = new MailMessage(); try { string smtpServer = ConfigurationManager.AppSettings["SMTPServer"].ToString(); string smtpPort = ConfigurationManager.AppSettings["SMTPPort"].ToString(); string fromEmailId = ConfigurationManager.AppSettings["TYEmailID"].ToString(); string fromEmailPassword = ConfigurationManager.AppSettings["TYEmailPassword"].ToString(); SmtpClient smtp = new SmtpClient(smtpServer, Convert.ToInt32(smtpPort)); smtp.UseDefaultCredentials = false; smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.Timeout = 100000; smtp.EnableSsl = true; smtp.Credentials = new System.Net.NetworkCredential(fromEmailId, fromEmailPassword); message.From = new MailAddress(this.config["from_email_id"].ToString()); message.Subject = this.subject; string[] to_email_id_list = to_email_ids.Split(','); foreach (string to_email_id in to_email_id_list) if(to_email_id.Length>0) message.To.Add(new MailAddress(to_email_id)); if (this.config["default_cc_email"].ToString().Length > 0) { if (cc_email_ids == null || cc_email_ids.Trim().Length == 0) { cc_email_ids = this.config["default_cc_email"].ToString(); } else { cc_email_ids = cc_email_ids + "," + this.config["default_cc_email"].ToString(); } } if (this.config["default_bcc_email"].ToString().Length > 0) { if (cc_email_ids == null || cc_email_ids.Trim().Length == 0) { bcc_email_ids = this.config["default_bcc_email"].ToString(); } else { bcc_email_ids = bcc_email_ids + "," + this.config["default_bcc_email"].ToString(); } } string[] cc_email_id_list = cc_email_ids.Split(','); foreach (string cc_email_id in cc_email_id_list) if(cc_email_id.Length>0) message.CC.Add(new MailAddress(cc_email_id)); string[] bcc_email_id_list = bcc_email_ids.Split(','); foreach (string bcc_email_id in bcc_email_id_list) if (bcc_email_id.Length > 0) message.Bcc.Add(new MailAddress(bcc_email_id)); message.BodyEncoding = System.Text.Encoding.UTF8; message.Body = this.body; message.IsBodyHtml = true; foreach (string temp_attachment in temp_attachments) message.Attachments.Add(new Attachment(temp_attachment)); smtp.Send(message); } catch (Exception ex) { logger.log("error", new Dictionary<string, object> { {"booking_id",booking_id}, {"email_ids",to_email_ids}, {"cc_email_ids",cc_email_ids}, {"bcc_email_ids",cc_email_ids}, {"type",type} }, ex.ToString()); if (message != null) message.Dispose(); return false; } finally { if (message != null) message.Dispose(); } return true; }
//sends the message. public bool send_email(int booking_id, string to_email_ids, string cc_email_ids, string bcc_email_ids) { Utils.clsLogger logger = new Utils.clsLogger(); if (to_email_ids == null) { to_email_ids = ""; } if (cc_email_ids == null) { cc_email_ids = ""; } if (bcc_email_ids == null) { bcc_email_ids = ""; } MailMessage message = new MailMessage(); try { string smtpServer = ConfigurationManager.AppSettings["SMTPServer"].ToString(); string smtpPort = ConfigurationManager.AppSettings["SMTPPort"].ToString(); string fromEmailId = ConfigurationManager.AppSettings["TYEmailID"].ToString(); string fromEmailPassword = ConfigurationManager.AppSettings["TYEmailPassword"].ToString(); SmtpClient smtp = new SmtpClient(smtpServer, Convert.ToInt32(smtpPort)); smtp.UseDefaultCredentials = false; smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.Timeout = 100000; smtp.EnableSsl = true; smtp.Credentials = new System.Net.NetworkCredential(fromEmailId, fromEmailPassword); message.From = new MailAddress(this.config["from_email_id"].ToString()); message.Subject = this.subject; string[] to_email_id_list = to_email_ids.Split(','); foreach (string to_email_id in to_email_id_list) { if (to_email_id.Length > 0) { message.To.Add(new MailAddress(to_email_id)); } } if (this.config["default_cc_email"].ToString().Length > 0) { if (cc_email_ids == null || cc_email_ids.Trim().Length == 0) { cc_email_ids = this.config["default_cc_email"].ToString(); } else { cc_email_ids = cc_email_ids + "," + this.config["default_cc_email"].ToString(); } } if (this.config["default_bcc_email"].ToString().Length > 0) { if (cc_email_ids == null || cc_email_ids.Trim().Length == 0) { bcc_email_ids = this.config["default_bcc_email"].ToString(); } else { bcc_email_ids = bcc_email_ids + "," + this.config["default_bcc_email"].ToString(); } } string[] cc_email_id_list = cc_email_ids.Split(','); foreach (string cc_email_id in cc_email_id_list) { if (cc_email_id.Length > 0) { message.CC.Add(new MailAddress(cc_email_id)); } } string[] bcc_email_id_list = bcc_email_ids.Split(','); foreach (string bcc_email_id in bcc_email_id_list) { if (bcc_email_id.Length > 0) { message.Bcc.Add(new MailAddress(bcc_email_id)); } } message.BodyEncoding = System.Text.Encoding.UTF8; message.Body = this.body; message.IsBodyHtml = true; foreach (string temp_attachment in temp_attachments) { message.Attachments.Add(new Attachment(temp_attachment)); } smtp.Send(message); } catch (Exception ex) { logger.log("error", new Dictionary <string, object> { { "booking_id", booking_id }, { "email_ids", to_email_ids }, { "cc_email_ids", cc_email_ids }, { "bcc_email_ids", cc_email_ids }, { "type", type } }, ex.ToString()); if (message != null) { message.Dispose(); } return(false); } finally { if (message != null) { message.Dispose(); } } return(true); }