ASP.NET C# code for MMS and SMS sending

ASP.NET C# code for MMS and SMS sending SearchSearch
Author Message
Strife Low
New member
Username: E_sllt

Post Number: 5
Registered: 04-2007
Posted on Monday, April 30, 2007 - 03:17 pm:   


quote:

Moderator Note: Updated examples for Sending MMS messages from VB .NET and C# .NET can be found in the following articles:

Send MMS Messages from C# .NET
Send MMS Messages from VB .NET




I have successfully build up an application to send MMS and SMS. To help those people developing in ASP.NET C#, here is the code :

SMS part:
<%@ Page Language="C#" %>
<%@Import namespace= 'System.Text' %>
<%@Import namespace= 'System.IO' %>
<%@Import namespace= 'System.Net' %>
<%@Import namespace= 'System.Web' %>
<%@Import namespace= 'System.Web.UI' %>
<%@Import namespace= 'System.Web.Services' %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
public void SendSMS()
{
UriBuilder urlBuilder = new UriBuilder();
urlBuilder.Host = "127.0.0.1";
urlBuilder.Port = 8800;

string PhoneNumber = "60123456789";
string message = "Just a simple text";

urlBuilder.Query = string.Format("PhoneNumber=%2B" + PhoneNumber + "&Text=" + message);

HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create(new Uri(urlBuilder.ToString(), false));
HttpWebResponse httpResponse = (HttpWebResponse)(httpReq.GetResponse());
}



protected void Page_Load(object sender, EventArgs e)
{
SendSMS();
}

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Send SMS</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>



MMS part:
<%@ Page Language="C#" %>
<%@Import namespace= 'System.Text' %>
<%@Import namespace= 'System.IO' %>
<%@Import namespace= 'System.Net' %>
<%@Import namespace= 'System.Web' %>
<%@Import namespace= 'System.Web.UI' %>
<%@Import namespace= 'System.Web.Services' %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
public void SendMMS()
{
UriBuilder urlBuilder = new UriBuilder();
urlBuilder.Host = "127.0.0.1";
urlBuilder.Port = 8800;

string PhoneNumber = "60123456789";
string message = "Just a simple text";
string subject = "MMS subject";
string fileName = "picture1.jpg";

urlBuilder.Query = string.Format("PhoneNumber=%2B" + PhoneNumber + "&MMSFrom=YourChoiceofName&MMSSubject=" + subject + "&MMSText=" + message + "&MMSFile=http://127.0.0.1/" + fileName);


HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create(new Uri(urlBuilder.ToString(), false));
HttpWebResponse httpResponse = (HttpWebResponse)(httpReq.GetResponse());
}



protected void Page_Load(object sender, EventArgs e)
{
SendMMS();
}

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Send SMS</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>



The sample phone number is +60123456789, however in sending SMS the query cannot define the "+" as string and send it so you need to use "%2B". But for sending MMS, I have tried to use "+" in the string and it works. The namespace I just simply import, you can test it and remove the unnecessary 1. I might upload the sample code for receive message and send out MMS and SMS(2 way).
Hayesha Somarathne
New member
Username: Hayesha

Post Number: 1
Registered: 05-2007
Posted on Thursday, May 17, 2007 - 05:10 am:   

hi,

MMS part:
<%@ Page Language="C#" %>
<%@Import namespace= 'System.Text' %>
<%@Import namespace= 'System.IO' %>
<%@Import namespace= 'System.Net' %>
<%@Import namespace= 'System.Web' %>
<%@Import namespace= 'System.Web.UI' %>
<%@Import namespace= 'System.Web.Services' %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
public void SendMMS()
{
UriBuilder urlBuilder = new UriBuilder();
urlBuilder.Host = "127.0.0.1";
urlBuilder.Port = 8800;

string PhoneNumber = "60123456789";
string message = "Just a simple text";
string subject = "MMS subject";
string fileName = "picture1.jpg";

urlBuilder.Query = string.Format("PhoneNumber=%2B" + PhoneNumber + "&MMSFrom=YourChoiceofName&MMSSubject=" + subject + "&MMSText=" + message + "&MMSFile=http://127.0.0.1/" + fileName);


HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create(new Uri(urlBuilder.ToString(), false));
HttpWebResponse httpResponse = (HttpWebResponse)(httpReq.GetResponse());
}



protected void Page_Load(object sender, EventArgs e)
{
SendMMS();
}

</script>



I'm planning to use the above code to send mms messages in my programme, so do i need to install any special software like Now SMS/MMS Gateway to get the use of the code.

Can't I sue any IPs other than 127.0.0.1 and what is the importance of it

hayesha.
Strife Low
New member
Username: E_sllt

Post Number: 6
Registered: 04-2007
Posted on Thursday, May 17, 2007 - 05:18 am:   

yes you need the NowSMS gateway.

127.0.0.1 is the localhost IP. You can replace it with your site IP. But it is normally only run on server side, so 127.0.0.1 will be ok.
Hayesha Somarathne
New member
Username: Hayesha

Post Number: 2
Registered: 05-2007
Posted on Thursday, May 17, 2007 - 05:36 am:   

Thanks
mainak
New member
Username: Mmmm

Post Number: 1
Registered: 09-2007
Posted on Monday, September 03, 2007 - 01:35 pm:   

i hv written

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Web.Services;
using System.Net;
using System.IO;
using System.Text;


public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SendSMS();
}
public void SendSMS()
{
UriBuilder urlBuilder = new UriBuilder();
urlBuilder.Host = "127.0.0.1";
urlBuilder.Port = 8800;

//string PhoneNumber = "60123456789";
string PhoneNumber = "919831851076";
string message = "Just a simple text";

urlBuilder.Query = string.Format("PhoneNumber=%2B" + PhoneNumber + "&Text=" + message);

HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create(new Uri(urlBuilder.ToString(), false));
HttpWebResponse httpResponse = (HttpWebResponse)(httpReq.GetResponse());

Response.Write(httpResponse.StatusCode.ToString());
Response.Write("sms send successfully");
}
}


for sending sms. but it does not work. in nowsms it shows sms sent in ques.but sms is not delivered.........
Bryce Norwood - NowSMS Support
Board Administrator
Username: Bryce

Post Number: 7492
Registered: 10-2002
Posted on Monday, September 17, 2007 - 11:40 pm:   

Can you send an SMS message using the NowSMS web interface?

If the SMS message is showing as queued, but not delivered ... this sounds like NowSMS is not fully configured.

Maybe there is some confusion about exactly what NowSMS is?

NowSMS is not a bulk SMS or MMS service provider. NowSMS is not a replacement for a bulk SMS or MMS service provider. You need a connection to an SMS service provider, or a GSM modem, before you can send any messages with NowSMS.

NowSMS is a middleware tool which simplifies the process of connecting to one or more of these service providers and/or managing one or more GSM modems.