Guest User

Untitled

a guest
Jul 10th, 2018
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.99 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Net;
  6. using System.IO;
  7. using System.Text.RegularExpressions;
  8. using System.Text;
  9.  
  10. /// <summary>
  11. /// Summary description for SendSMSAndEmailClass
  12. /// </summary>
  13. public class SendSMSAndEmailClass
  14. {
  15. public SendSMSAndEmailClass()
  16. {
  17. //
  18. // TODO: Add constructor logic here
  19. //
  20. }
  21.  
  22. public void SendSMSAndEmailMethod(string strMessage, string Subject, string ToName, string ToEmail, string strMob)
  23. {
  24. try
  25. {
  26. SendMail(ToEmail, Subject, strMessage);
  27.  
  28. }
  29. catch
  30. {
  31. }
  32. try
  33. {
  34. if (strMob != null)
  35. {
  36. SendSMS(strMob, strMessage);
  37. }
  38. }
  39. catch
  40. {
  41. }
  42. }
  43.  
  44. public static void SendMail(string toAddress, string subject, string body)
  45. {
  46. //Read SMTP Server Name or IP from Config xml file
  47. string SmtpServer = "119.18.55.188";
  48. //Read User Name from Config xml file
  49. string SmtpUserName = System.Configuration.ConfigurationManager.AppSettings["EmailUserName"];
  50. //Read User Password from Config xml file
  51. string SmtpUserPass = System.Configuration.ConfigurationManager.AppSettings["EmailPassword"];
  52. //Read port setting from Config xml file
  53. string smtpPort = "25";
  54. string FromName = "CORE";
  55. System.Net.Mail.SmtpClient smtpSend = new System.Net.Mail.SmtpClient(SmtpServer);
  56. System.Net.Mail.MailMessage emailMessage = new System.Net.Mail.MailMessage();
  57. emailMessage.To.Add(toAddress);
  58. string BCCAddress = "core.vendorreg@gmail.com";
  59. emailMessage.Bcc.Add(BCCAddress);
  60. string FromEmail = SmtpUserName;
  61. emailMessage.From = new System.Net.Mail.MailAddress(FromEmail, FromName);
  62. emailMessage.Subject = subject;
  63. emailMessage.Body = body;
  64. emailMessage.IsBodyHtml = true;
  65. if ((!Regex.IsMatch(emailMessage.Body, "^([0-9a-z!@#\\$\\%\\^&\\*\\(\\)\\-=_\\+])", RegexOptions.IgnoreCase) || !Regex.IsMatch(emailMessage.Subject, "^([0-9a-z!@#\\$\\%\\^&\\*\\(\\)\\-=_\\+])", RegexOptions.IgnoreCase)))
  66. {
  67. emailMessage.BodyEncoding = Encoding.Unicode;
  68. }
  69. if (((((SmtpUserName) != null)) && ((((SmtpUserPass) != null)) && (((smtpPort) != null)))))
  70. {
  71. smtpSend.Port = Convert.ToInt32(smtpPort);
  72. smtpSend.UseDefaultCredentials = false;
  73. smtpSend.Credentials = new System.Net.NetworkCredential(SmtpUserName, SmtpUserPass);
  74. }
  75. try
  76. {
  77. smtpSend.Send(emailMessage);
  78.  
  79. }
  80. catch (Exception ex)
  81. {
  82. }
  83. }
  84.  
  85.  
  86. protected string SendSMS(string strRecip, string strMsgText)
  87. {
  88. string functionReturnValue = null;
  89. try
  90. {
  91. string strSender = "CORE";
  92. strSender = "919860609000";
  93. strMsgText = encode_message(strMsgText);
  94. Uri objURI = new Uri("http://bulksms.sms2india.info/sendsms.php?user=hai.abb&password=12345678&sender=VSHELP&countrycode=91&PhoneNumber=" + strRecip + "&text=" + strMsgText + "&gateway=UES3B2ZX");
  95. WebRequest objWebRequest = WebRequest.Create(objURI);
  96. WebResponse objWebResponse = objWebRequest.GetResponse();
  97. Stream objStream = objWebResponse.GetResponseStream();
  98. StreamReader objStreamReader;
  99. objStreamReader = new StreamReader(objStream);
  100. string strHTML = Convert.ToString(objStreamReader.ReadToEnd());
  101. functionReturnValue = strHTML;
  102. }
  103. catch
  104. {
  105. }
  106. return functionReturnValue;
  107. }
  108. public string encode_message(string strMsgText)
  109. {
  110. try
  111. {
  112. if (strMsgText.Contains("/") == true)
  113. {
  114. strMsgText = strMsgText.Replace("/", "%2F");
  115. }
  116. if (strMsgText.Contains("&") == true)
  117. {
  118. strMsgText = strMsgText.Replace("&", "%26");
  119. }
  120. if (strMsgText.Contains(";") == true)
  121. {
  122. strMsgText = strMsgText.Replace(";", "%3B");
  123. }
  124. if (strMsgText.Contains("?") == true)
  125. {
  126. strMsgText = strMsgText.Replace("?", "%3F");
  127. }
  128. if (strMsgText.Contains(":") == true)
  129. {
  130. strMsgText = strMsgText.Replace(":", "%3A");
  131. }
  132. if (strMsgText.Contains("#") == true)
  133. {
  134. strMsgText = strMsgText.Replace("#", "%23");
  135. }
  136. if (strMsgText.Contains("=") == true)
  137. {
  138. strMsgText = strMsgText.Replace("=", "%3D");
  139. }
  140. if (strMsgText.Contains("+") == true)
  141. {
  142. strMsgText = strMsgText.Replace("+", "%2B");
  143. }
  144. if (strMsgText.Contains("$") == true)
  145. {
  146. strMsgText = strMsgText.Replace("$", "%24");
  147. }
  148. //If strMsgText.Contains(",") = True Then
  149. // strMsgText = strMsgText.Replace(",", "%2C")
  150. //End If
  151. //If strMsgText.Contains(" ") = True Then
  152. // strMsgText = strMsgText.Replace(" ", "%20")
  153. //End If
  154. //If strMsgText.Contains("%") = True Then
  155. // strMsgText = strMsgText.Replace("%", "%25")
  156. //End If
  157. if (strMsgText.Contains("<") == true)
  158. {
  159. strMsgText = strMsgText.Replace("<", "%3C");
  160. }
  161. if (strMsgText.Contains(">") == true)
  162. {
  163. strMsgText = strMsgText.Replace(">", "%3E");
  164. }
  165. if (strMsgText.Contains("~") == true)
  166. {
  167. strMsgText = strMsgText.Replace("~", "%7E");
  168. }
  169.  
  170.  
  171. }
  172. catch (Exception ex)
  173. {
  174. }
  175.  
  176. return strMsgText;
  177. }
  178. }
Add Comment
Please, Sign In to add comment