472,127 Members | 2,074 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

ASP.NET: Sending SMS - BulkSMSGateway returns error 4006

87
Hi,

I use BulkSMSGateway - ATSMS.dll for sending SMS from ASP.NET.

When I click Connect button, I am able to connect to the mobile using bluetooth successfully from my WebPage.

But when i click Send button, the oGsmModem returns error
e.errorcode=4006 in the oGsmModem_OutboxSMSSent event.

But i can send SMS successfully using VB.NET Windows Appication.

Why it returns error in web form alone?

Please help me to send SMS from my Web Page.

Thanks in advance...
Apr 2 '10 #1
3 3745
CroCrew
564 Expert 512MB
Hello Ananthu,

A few years back I created an example in Classic ASP for a member to send SMS text to phones via a website. [See here]

I took that code and changed it up to work in the dot.net environment. I have not tested it out but I think it should work for you. This way you don’t have to use 3rd party addons.

Happy Coding,
CroCrew~


Default1.aspx
Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default1.aspx.vb" Inherits="Default1" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4.     <head runat="server">
  5.         <title></title>
  6.     </head>
  7.     <body>
  8.         <form id="form1" runat="server">
  9.             <div>
  10.                 <table border="0"> 
  11.                     <tr> 
  12.                         <td>Phone Number:</td> 
  13.                         <td><asp:TextBox ID="PhoneNumber" runat="server" /><font size="1">(only enter the numbers) example 6045555555</font></td> 
  14.                     </tr> 
  15.                     <tr> 
  16.                         <td>Select Your Carrier</td> 
  17.                         <td> 
  18.                             <asp:DropDownList ID="Carrier" runat="server">
  19.                                 <asp:ListItem Value="@tmomail.net" Text="T-Mobile (USA)" />
  20.                                 <asp:ListItem Value="@message.alltel.com" Text="Alltel Wireless" />
  21.                                 <asp:ListItem Value="@mms.att.net" Text="AT&T Mobility (formerly Cingular)" />
  22.                                 <asp:ListItem Value="@cingularme.com" Text="Cingular (Postpaid)" />
  23.                                 <asp:ListItem Value="@cwemail.com" Text="Centennial Wireless" />
  24.                                 <asp:ListItem Value="@cingularme.com" Text="Cingular (GoPhone prepaid)" />
  25.                                 <asp:ListItem Value="@fido.ca" Text="Fido (Canada)" />
  26.                                 <asp:ListItem Value="@pcs.rogers.com" Text="Rogers (Canada)" />
  27.                                 <asp:ListItem Value="@messaging.sprintpcs.com" Text="Sprint (PCS)" />
  28.                                 <asp:ListItem Value="@page.nextel.com" Text="Sprint (Nextel)" />
  29.                                 <asp:ListItem Value="@vtext.com" Text="Verizon" />
  30.                                 <asp:ListItem Value="@vmobl.com" Text="Virgin Mobile (USA)" />
  31.                                 <asp:ListItem Value="@vmobile.ca" Text="Virgin Mobile (Canada)" />
  32.                                 <asp:ListItem Value="@mmst5.tracfone.com" Text="Tracfone (prepaid)" />
  33.                             </asp:DropDownList>
  34.                         </td> 
  35.                     </tr> 
  36.                     <tr> 
  37.                         <td colspan="2"> 
  38.                             <textarea id="YourMessage" runat="server" cols="142" rows="5" style="width:500px">Only 142 characters can be sent!</textarea> 
  39.                         </td> 
  40.                     </tr> 
  41.                     <tr><td colspan="2"><asp:Button ID="Send" runat="server" Text="Send Message to Phone" /></td></tr> 
  42.                 </table> 
  43.                 <p>*Standard text messaging rates apply.</p>
  44.             </div>
  45.         </form>
  46.     </body>
  47. </html>
  48.  

Default1.aspx.vb
Expand|Select|Wrap|Line Numbers
  1. Imports System.Net.Mail
  2.  
  3. Partial Class Default1
  4.     Inherits System.Web.UI.Page
  5.  
  6.     Protected Sub Send_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Send.Click
  7.         Try
  8.             Dim oMail As New MailMessage
  9.             With oMail
  10.                 .From = New MailAddress("YourMail@MyEmail.com")
  11.                 .To.Add(PhoneNumber.Text & Carrier.SelectedValue)
  12.                 .Subject = ""
  13.                 .Body = YourMessage.Value
  14.                 .IsBodyHtml = True
  15.             End With
  16.  
  17.             Dim oSMTP As New SmtpClient
  18.             With oSMTP
  19.                 .Host = "mail.yourServer.org"
  20.                 .Credentials = New System.Net.NetworkCredential("YourMail@MyEmail.com", "Password")
  21.                 .Send(oMail)
  22.             End With
  23.         Catch ex As Exception
  24.             Response.Write(ex)
  25.             Response.End()
  26.         End Try
  27.     End Sub
  28. End Class
  29.  
Here is a link to more Email to SMS Gateways: http://en.wikipedia.org/wiki/List_of...ng_SMS_transit
Apr 2 '10 #2
Ananthu
87
Hi,

This is my code for sending SMS using BulkSMSGateway - ATSMS.dll.
Expand|Select|Wrap|Line Numbers
  1. Imports ATSMS
  2. Imports ATSMS.SMS
  3.  
  4. Partial Class bulkSMS
  5.     Inherits System.Web.UI.Page
  6.  
  7.     Private Const PHONE_BOOK As String = "phonebook.txt"
  8.  
  9.     Private m_strPhoneBook As String
  10.  
  11.     Private WithEvents oGsmModem As New GSMModem
  12.  
  13.     Dim tbl As String
  14.     Dim str As String
  15.     Dim item As Array = Array.CreateInstance(GetType(String), 100)
  16.     Dim cs As clsEPAS = New clsEPAS
  17.     Dim fieldname As String
  18.     Dim fieldvalue As String
  19.  
  20.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As       System.EventArgs) Handles Me.Load
  21.         Dim f As Integer
  22.         f = cs.connect
  23.         If Not IsPostBack Then
  24.             'CheckForIllegalCrossThreadCalls = False
  25.  
  26.             tbl = "tbl_TimeDetails"
  27.             fieldname = "time_session"
  28.             item = cs.getname(tbl, fieldname)
  29.             ddlSession.Items.Add("Select")
  30.             For i As Integer = 0 To item.Length - 1
  31.                 If IsNothing(item(i)) Then
  32.                     Exit For
  33.                 Else
  34.                     ddlSession.Items.Add(item(i))
  35.                 End If
  36.             Next
  37.             For i As Integer = 1 To 50
  38.                 ddlComPort.Items.Add("COM" & i)
  39.             Next
  40.             For i As Integer = 4 To 8
  41.                 ddlDataBit.Items.Add(i)
  42.             Next
  43.         End If
  44.     End Sub
  45.  
  46.     Protected Sub btnConnect_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnConnect.Click
  47.         If ddlComPort.Text = String.Empty Then
  48.             Response.Write("COM Port must be selected")
  49.             Return
  50.         End If
  51.  
  52.         oGsmModem.Port = ddlComPort.Text
  53.  
  54.         If ddlBaudRate.Text <> String.Empty Then
  55.             oGsmModem.BaudRate = Convert.ToInt32(ddlBaudRate.Text)
  56.         End If
  57.  
  58.         If ddlDataBit.Text <> String.Empty Then
  59.             oGsmModem.DataBits = Convert.ToInt32(ddlDataBit.Text)
  60.         End If
  61.  
  62.         If ddlStopBit.Text <> String.Empty Then
  63.             Select Case ddlStopBit.Text
  64.                 Case "1"
  65.                     oGsmModem.StopBits = Common.EnumStopBits.One
  66.                 Case "1.5"
  67.                     oGsmModem.StopBits = Common.EnumStopBits.OnePointFive
  68.                 Case "2"
  69.                     oGsmModem.StopBits = Common.EnumStopBits.Two
  70.             End Select
  71.         End If
  72.  
  73.         If ddlFlowControl.Text <> String.Empty Then
  74.             Select Case ddlFlowControl.Text
  75.                 Case "None"
  76.                     oGsmModem.FlowControl = Common.EnumFlowControl.None
  77.                 Case "Hardware"
  78.                     oGsmModem.FlowControl = Common.EnumFlowControl.RTS_CTS
  79.                 Case "Xon/Xoff"
  80.                     oGsmModem.FlowControl = Common.EnumFlowControl.Xon_Xoff
  81.             End Select
  82.         End If
  83.  
  84.         Try
  85.             oGsmModem.Connect()
  86.         Catch ex As Exception
  87.             Response.Write(ex.Message)
  88.             Return
  89.         End Try
  90.  
  91.         Try
  92.             oGsmModem.NewMessageIndication = True
  93.         Catch ex As Exception
  94.  
  95.         End Try
  96.  
  97.         btnSend.Enabled = True
  98.         btnDisconnect.Enabled = True
  99.         btnConnect.Enabled = False
  100.  
  101.         oGsmModem.AutoDeleteSentMessage = True
  102.         Response.Write("Connected to phone successfully !")
  103.     End Sub
  104.  
  105.     Protected Sub btnDisconnect_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDisconnect.Click
  106.         Try
  107.             oGsmModem.Disconnect()
  108.         Catch ex As Exception
  109.             Response.Write(ex.Message)
  110.         End Try
  111.  
  112.         btnSend.Enabled = False
  113.         btnDisconnect.Enabled = False
  114.         btnConnect.Enabled = True
  115.     End Sub
  116.  
  117.     Private Sub Initialize()
  118.         ' Read from the phone book
  119.         'Dim strContent As String
  120.         'm_strPhoneBook = Application.StartupPath & "\" & PHONE_BOOK
  121.         'If My.Computer.FileSystem.FileExists(m_strPhoneBook) Then
  122.         '    strContent = My.Computer.FileSystem.ReadAllText(m_strPhoneBook)
  123.         '    Dim lines() As String = strContent.Split(ControlChars.CrLf)
  124.         '    Dim i As Integer
  125.         '    For i = 0 To lines.Length - 1
  126.         '        lstMobileNumber.Items.Add(lines(i))
  127.         '    Next
  128.         'End If
  129.     End Sub
  130.  
  131.     Protected Sub btnSend_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSend.Click
  132.         If txtMessage.Text.Trim = String.Empty Then
  133.             Response.Write("Message must not be empty !")
  134.             Return
  135.         End If
  136.  
  137.         If StringUtils.IsUnicode(txtMessage.Text) Then
  138.             oGsmModem.Encoding = Common.EnumEncoding.Unicode_16Bit
  139.         Else
  140.             oGsmModem.Encoding = Common.EnumEncoding.GSM_Default_7Bit
  141.         End If
  142.  
  143.         For Each item As String In lstMobileNumber.Items.ToString
  144.             If item.Trim <> String.Empty Then
  145.                 oGsmModem.SendSMSToOutbox(item.Trim, txtMessage.Text.Trim)
  146.             End If
  147.         Next
  148.  
  149.         Response.Write("Message is queued for sending !")
  150.     End Sub
  151.  
  152.     Private Sub oGsmModem_OutboxSMSSent(ByVal e As ATSMS.OutboxSMSSentEventArgs) Handles oGsmModem.OutboxSMSSent
  153.         If e.ErrorCode > 0 Then
  154.             txtDelivaryReport.Text = txtDelivaryReport.Text & "Error sending message to " & e.DestinationNumber & ". " & e.ErrorDescription & ControlChars.CrLf
  155.         Else
  156.             txtDelivaryReport.Text = txtDelivaryReport.Text & "Message is delivered to " & e.DestinationNumber & ControlChars.CrLf
  157.         End If
  158.     End Sub
  159.  
  160. End Class
I am able to connect to phone successfully. btnSend_click code is working properly. But I get e.errorcode=4006 in oGsmModem_OutboxSMSSent event after btnSend_click event.

The same sms codings work successfully using windows application. But in web application only, it returns e.errorcode=4006. I am unable to send SMS.

Please help me...

Thanks in advance.
Apr 6 '10 #3
CroCrew
564 Expert 512MB
TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.

Thanks,
CroCrew~
Apr 7 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

47 posts views Thread by Mountain Bikn' Guy | last post: by
3 posts views Thread by Robert A. van Ginkel | last post: by
7 posts views Thread by Mark Waser | last post: by
4 posts views Thread by shamirza | last post: by
2 posts views Thread by =?Utf-8?B?R3JlZ0lJ?= | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.