Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Net;
- using System.IO;
- using System.Text.RegularExpressions;
- using System.Text;
- /// <summary>
- /// Summary description for SendSMSAndEmailClass
- /// </summary>
- public class SendSMSAndEmailClass
- {
- public SendSMSAndEmailClass()
- {
- //
- // TODO: Add constructor logic here
- //
- }
- public void SendSMSAndEmailMethod(string strMessage, string Subject, string ToName, string ToEmail, string strMob)
- {
- try
- {
- SendMail(ToEmail, Subject, strMessage);
- }
- catch
- {
- }
- try
- {
- if (strMob != null)
- {
- SendSMS(strMob, strMessage);
- }
- }
- catch
- {
- }
- }
- public static void SendMail(string toAddress, string subject, string body)
- {
- //Read SMTP Server Name or IP from Config xml file
- string SmtpServer = "119.18.55.188";
- //Read User Name from Config xml file
- string SmtpUserName = System.Configuration.ConfigurationManager.AppSettings["EmailUserName"];
- //Read User Password from Config xml file
- string SmtpUserPass = System.Configuration.ConfigurationManager.AppSettings["EmailPassword"];
- //Read port setting from Config xml file
- string smtpPort = "25";
- string FromName = "CORE";
- System.Net.Mail.SmtpClient smtpSend = new System.Net.Mail.SmtpClient(SmtpServer);
- System.Net.Mail.MailMessage emailMessage = new System.Net.Mail.MailMessage();
- emailMessage.To.Add(toAddress);
- string BCCAddress = "core.vendorreg@gmail.com";
- emailMessage.Bcc.Add(BCCAddress);
- string FromEmail = SmtpUserName;
- emailMessage.From = new System.Net.Mail.MailAddress(FromEmail, FromName);
- emailMessage.Subject = subject;
- emailMessage.Body = body;
- emailMessage.IsBodyHtml = true;
- if ((!Regex.IsMatch(emailMessage.Body, "^([0-9a-z!@#\\$\\%\\^&\\*\\(\\)\\-=_\\+])", RegexOptions.IgnoreCase) || !Regex.IsMatch(emailMessage.Subject, "^([0-9a-z!@#\\$\\%\\^&\\*\\(\\)\\-=_\\+])", RegexOptions.IgnoreCase)))
- {
- emailMessage.BodyEncoding = Encoding.Unicode;
- }
- if (((((SmtpUserName) != null)) && ((((SmtpUserPass) != null)) && (((smtpPort) != null)))))
- {
- smtpSend.Port = Convert.ToInt32(smtpPort);
- smtpSend.UseDefaultCredentials = false;
- smtpSend.Credentials = new System.Net.NetworkCredential(SmtpUserName, SmtpUserPass);
- }
- try
- {
- smtpSend.Send(emailMessage);
- }
- catch (Exception ex)
- {
- }
- }
- protected string SendSMS(string strRecip, string strMsgText)
- {
- string functionReturnValue = null;
- try
- {
- string strSender = "CORE";
- strSender = "919860609000";
- strMsgText = encode_message(strMsgText);
- 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");
- WebRequest objWebRequest = WebRequest.Create(objURI);
- WebResponse objWebResponse = objWebRequest.GetResponse();
- Stream objStream = objWebResponse.GetResponseStream();
- StreamReader objStreamReader;
- objStreamReader = new StreamReader(objStream);
- string strHTML = Convert.ToString(objStreamReader.ReadToEnd());
- functionReturnValue = strHTML;
- }
- catch
- {
- }
- return functionReturnValue;
- }
- public string encode_message(string strMsgText)
- {
- try
- {
- if (strMsgText.Contains("/") == true)
- {
- strMsgText = strMsgText.Replace("/", "%2F");
- }
- if (strMsgText.Contains("&") == true)
- {
- strMsgText = strMsgText.Replace("&", "%26");
- }
- if (strMsgText.Contains(";") == true)
- {
- strMsgText = strMsgText.Replace(";", "%3B");
- }
- if (strMsgText.Contains("?") == true)
- {
- strMsgText = strMsgText.Replace("?", "%3F");
- }
- if (strMsgText.Contains(":") == true)
- {
- strMsgText = strMsgText.Replace(":", "%3A");
- }
- if (strMsgText.Contains("#") == true)
- {
- strMsgText = strMsgText.Replace("#", "%23");
- }
- if (strMsgText.Contains("=") == true)
- {
- strMsgText = strMsgText.Replace("=", "%3D");
- }
- if (strMsgText.Contains("+") == true)
- {
- strMsgText = strMsgText.Replace("+", "%2B");
- }
- if (strMsgText.Contains("$") == true)
- {
- strMsgText = strMsgText.Replace("$", "%24");
- }
- //If strMsgText.Contains(",") = True Then
- // strMsgText = strMsgText.Replace(",", "%2C")
- //End If
- //If strMsgText.Contains(" ") = True Then
- // strMsgText = strMsgText.Replace(" ", "%20")
- //End If
- //If strMsgText.Contains("%") = True Then
- // strMsgText = strMsgText.Replace("%", "%25")
- //End If
- if (strMsgText.Contains("<") == true)
- {
- strMsgText = strMsgText.Replace("<", "%3C");
- }
- if (strMsgText.Contains(">") == true)
- {
- strMsgText = strMsgText.Replace(">", "%3E");
- }
- if (strMsgText.Contains("~") == true)
- {
- strMsgText = strMsgText.Replace("~", "%7E");
- }
- }
- catch (Exception ex)
- {
- }
- return strMsgText;
- }
- }
Add Comment
Please, Sign In to add comment