Click here to Skip to main content
15,885,757 members
Articles / Programming Languages / C#

Sending SMS from Computer to Mobile using SMS Driver Gateway

Rate me:
Please Sign up or sign in to vote.
1.58/5 (16 votes)
13 May 2005CPOL 117.6K   26  
This is a sample code for sending SMS from .NET to any Mobile in the World. This will use SMSDriver Gateway. The Sample code will work only for Mobile in India.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace SMSDriverSample1
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.TextBox txtUser;
		private System.Windows.Forms.TextBox txtPwd;
		private System.Windows.Forms.TextBox txtURL;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.TextBox txtHOST;
		private System.Windows.Forms.Label lblHost;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.TextBox txtSender;
		private System.Windows.Forms.TextBox txtMsg;
		private System.Windows.Forms.Label Message;
		private System.Windows.Forms.TextBox txtHTML;
		private System.Windows.Forms.Button Send;
		private System.Windows.Forms.TextBox txtNumber;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.txtUser = new System.Windows.Forms.TextBox();
			this.txtPwd = new System.Windows.Forms.TextBox();
			this.Send = new System.Windows.Forms.Button();
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.txtURL = new System.Windows.Forms.TextBox();
			this.label3 = new System.Windows.Forms.Label();
			this.txtHOST = new System.Windows.Forms.TextBox();
			this.lblHost = new System.Windows.Forms.Label();
			this.txtNumber = new System.Windows.Forms.TextBox();
			this.label4 = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.txtSender = new System.Windows.Forms.TextBox();
			this.txtMsg = new System.Windows.Forms.TextBox();
			this.Message = new System.Windows.Forms.Label();
			this.txtHTML = new System.Windows.Forms.TextBox();
			this.SuspendLayout();
			// 
			// txtUser
			// 
			this.txtUser.Location = new System.Drawing.Point(144, 16);
			this.txtUser.Name = "txtUser";
			this.txtUser.Size = new System.Drawing.Size(360, 20);
			this.txtUser.TabIndex = 0;
			this.txtUser.Text = "";
			this.txtUser.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
			// 
			// txtPwd
			// 
			this.txtPwd.Location = new System.Drawing.Point(144, 48);
			this.txtPwd.Name = "txtPwd";
			this.txtPwd.PasswordChar = '*';
			this.txtPwd.Size = new System.Drawing.Size(360, 20);
			this.txtPwd.TabIndex = 1;
			this.txtPwd.Text = "";
			// 
			// Send
			// 
			this.Send.Location = new System.Drawing.Point(168, 360);
			this.Send.Name = "Send";
			this.Send.Size = new System.Drawing.Size(112, 40);
			this.Send.TabIndex = 2;
			this.Send.Text = "Send";
			this.Send.Click += new System.EventHandler(this.button1_Click);
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(24, 16);
			this.label1.Name = "label1";
			this.label1.TabIndex = 3;
			this.label1.Text = "SMSUser";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(24, 48);
			this.label2.Name = "label2";
			this.label2.TabIndex = 4;
			this.label2.Text = "SMSPassword";
			// 
			// txtURL
			// 
			this.txtURL.Location = new System.Drawing.Point(144, 80);
			this.txtURL.Name = "txtURL";
			this.txtURL.Size = new System.Drawing.Size(360, 20);
			this.txtURL.TabIndex = 5;
			this.txtURL.Text = "http://post.smsdriver.com/smshurricane3.0.asp";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(24, 80);
			this.label3.Name = "label3";
			this.label3.TabIndex = 6;
			this.label3.Text = "SMSURL";
			// 
			// txtHOST
			// 
			this.txtHOST.Location = new System.Drawing.Point(144, 112);
			this.txtHOST.Name = "txtHOST";
			this.txtHOST.Size = new System.Drawing.Size(360, 20);
			this.txtHOST.TabIndex = 7;
			this.txtHOST.Text = "post.smsdriver.com";
			// 
			// lblHost
			// 
			this.lblHost.Location = new System.Drawing.Point(24, 112);
			this.lblHost.Name = "lblHost";
			this.lblHost.TabIndex = 8;
			this.lblHost.Text = "SMSHost";
			// 
			// txtNumber
			// 
			this.txtNumber.Location = new System.Drawing.Point(144, 152);
			this.txtNumber.Name = "txtNumber";
			this.txtNumber.Size = new System.Drawing.Size(360, 20);
			this.txtNumber.TabIndex = 9;
			this.txtNumber.Text = "+919840798505";
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(24, 152);
			this.label4.Name = "label4";
			this.label4.TabIndex = 10;
			this.label4.Text = "Number";
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(24, 192);
			this.label5.Name = "label5";
			this.label5.TabIndex = 11;
			this.label5.Text = "Sender";
			// 
			// txtSender
			// 
			this.txtSender.Location = new System.Drawing.Point(144, 184);
			this.txtSender.Name = "txtSender";
			this.txtSender.Size = new System.Drawing.Size(360, 20);
			this.txtSender.TabIndex = 12;
			this.txtSender.Text = "sudeesh";
			// 
			// txtMsg
			// 
			this.txtMsg.Location = new System.Drawing.Point(144, 216);
			this.txtMsg.Name = "txtMsg";
			this.txtMsg.Size = new System.Drawing.Size(360, 20);
			this.txtMsg.TabIndex = 13;
			this.txtMsg.Text = "Sample Msg from SMS Test Application";
			// 
			// Message
			// 
			this.Message.Location = new System.Drawing.Point(24, 224);
			this.Message.Name = "Message";
			this.Message.TabIndex = 14;
			this.Message.Text = "label6";
			// 
			// txtHTML
			// 
			this.txtHTML.Location = new System.Drawing.Point(24, 256);
			this.txtHTML.Multiline = true;
			this.txtHTML.Name = "txtHTML";
			this.txtHTML.Size = new System.Drawing.Size(480, 88);
			this.txtHTML.TabIndex = 15;
			this.txtHTML.Text = "";
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(520, 462);
			this.Controls.Add(this.txtHTML);
			this.Controls.Add(this.Message);
			this.Controls.Add(this.txtMsg);
			this.Controls.Add(this.txtSender);
			this.Controls.Add(this.label5);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.txtNumber);
			this.Controls.Add(this.lblHost);
			this.Controls.Add(this.txtHOST);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.txtURL);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.Send);
			this.Controls.Add(this.txtPwd);
			this.Controls.Add(this.txtUser);
			this.Name = "Form1";
			this.Text = "Form1";
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			SMSDriver.SmsDriverLibClass clssms = new SMSDriver.SmsDriverLibClass();
			clssms.HOST = txtHOST.Text;
			clssms.smsUSER = txtUser.Text;
			clssms.smsPASSWORD = txtPwd.Text;
			clssms.URL = txtURL.Text;
			clssms.Add_Gsm(txtNumber.Text);
			clssms.Send_Sms(10,txtSender.Text,txtMsg.Text,"2","file.sms","");
			txtHTML.Text  = clssms.HTML;
				
		}

		private void textBox1_TextChanged(object sender, System.EventArgs e)
		{
		
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions