ASP.NET: Sending SMS - BulkSMSGateway returns error 4006

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ananthu
    New Member
    • Sep 2007
    • 87

    ASP.NET: Sending SMS - BulkSMSGateway returns error 4006

    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=400 6 in the oGsmModem_Outbo xSMSSent 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...
  • CroCrew
    Recognized Expert Contributor
    • Jan 2008
    • 564

    #2
    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
    Code:
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default1.aspx.vb" Inherits="Default1" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head runat="server">
            <title></title>
        </head>
        <body>
            <form id="form1" runat="server">
                <div>
                    <table border="0"> 
                        <tr> 
                            <td>Phone Number:</td> 
                            <td><asp:TextBox ID="PhoneNumber" runat="server" /><font size="1">(only enter the numbers) example 6045555555</font></td> 
                        </tr> 
                        <tr> 
                            <td>Select Your Carrier</td> 
                            <td> 
                                <asp:DropDownList ID="Carrier" runat="server">
                                    <asp:ListItem Value="@tmomail.net" Text="T-Mobile (USA)" />
                                    <asp:ListItem Value="@message.alltel.com" Text="Alltel Wireless" />
                                    <asp:ListItem Value="@mms.att.net" Text="AT&T Mobility (formerly Cingular)" />
                                    <asp:ListItem Value="@cingularme.com" Text="Cingular (Postpaid)" />
                                    <asp:ListItem Value="@cwemail.com" Text="Centennial Wireless" />
                                    <asp:ListItem Value="@cingularme.com" Text="Cingular (GoPhone prepaid)" />
                                    <asp:ListItem Value="@fido.ca" Text="Fido (Canada)" />
                                    <asp:ListItem Value="@pcs.rogers.com" Text="Rogers (Canada)" />
                                    <asp:ListItem Value="@messaging.sprintpcs.com" Text="Sprint (PCS)" />
                                    <asp:ListItem Value="@page.nextel.com" Text="Sprint (Nextel)" />
                                    <asp:ListItem Value="@vtext.com" Text="Verizon" />
                                    <asp:ListItem Value="@vmobl.com" Text="Virgin Mobile (USA)" />
                                    <asp:ListItem Value="@vmobile.ca" Text="Virgin Mobile (Canada)" />
                                    <asp:ListItem Value="@mmst5.tracfone.com" Text="Tracfone (prepaid)" />
                                </asp:DropDownList>
                            </td> 
                        </tr> 
                        <tr> 
                            <td colspan="2"> 
                                <textarea id="YourMessage" runat="server" cols="142" rows="5" style="width:500px">Only 142 characters can be sent!</textarea> 
                            </td> 
                        </tr> 
                        <tr><td colspan="2"><asp:Button ID="Send" runat="server" Text="Send Message to Phone" /></td></tr> 
                    </table> 
                    <p>*Standard text messaging rates apply.</p>
                </div>
            </form>
        </body>
    </html>

    Default1.aspx.v b
    Code:
    Imports System.Net.Mail
    
    Partial Class Default1
        Inherits System.Web.UI.Page
    
        Protected Sub Send_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Send.Click
            Try
                Dim oMail As New MailMessage
                With oMail
                    .From = New MailAddress("YourMail@MyEmail.com")
                    .To.Add(PhoneNumber.Text & Carrier.SelectedValue)
                    .Subject = ""
                    .Body = YourMessage.Value
                    .IsBodyHtml = True
                End With
    
                Dim oSMTP As New SmtpClient
                With oSMTP
                    .Host = "mail.yourServer.org"
                    .Credentials = New System.Net.NetworkCredential("YourMail@MyEmail.com", "Password")
                    .Send(oMail)
                End With
            Catch ex As Exception
                Response.Write(ex)
                Response.End()
            End Try
        End Sub
    End Class
    Here is a link to more Email to SMS Gateways: http://en.wikipedia.org/wiki/List_of...ng_SMS_transit

    Comment

    • Ananthu
      New Member
      • Sep 2007
      • 87

      #3
      Hi,

      This is my code for sending SMS using BulkSMSGateway - ATSMS.dll.
      Code:
      Imports ATSMS
      Imports ATSMS.SMS
      
      Partial Class bulkSMS
          Inherits System.Web.UI.Page
      
          Private Const PHONE_BOOK As String = "phonebook.txt"
      
          Private m_strPhoneBook As String
      
          Private WithEvents oGsmModem As New GSMModem
      
          Dim tbl As String
          Dim str As String
          Dim item As Array = Array.CreateInstance(GetType(String), 100)
          Dim cs As clsEPAS = New clsEPAS
          Dim fieldname As String
          Dim fieldvalue As String
      
          Protected Sub Page_Load(ByVal sender As Object, ByVal e As       System.EventArgs) Handles Me.Load
              Dim f As Integer
              f = cs.connect
              If Not IsPostBack Then
                  'CheckForIllegalCrossThreadCalls = False
      
                  tbl = "tbl_TimeDetails"
                  fieldname = "time_session"
                  item = cs.getname(tbl, fieldname)
                  ddlSession.Items.Add("Select")
                  For i As Integer = 0 To item.Length - 1
                      If IsNothing(item(i)) Then
                          Exit For
                      Else
                          ddlSession.Items.Add(item(i))
                      End If
                  Next
                  For i As Integer = 1 To 50
                      ddlComPort.Items.Add("COM" & i)
                  Next
                  For i As Integer = 4 To 8
                      ddlDataBit.Items.Add(i)
                  Next
              End If
          End Sub
      
          Protected Sub btnConnect_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnConnect.Click
              If ddlComPort.Text = String.Empty Then
                  Response.Write("COM Port must be selected")
                  Return
              End If
      
              oGsmModem.Port = ddlComPort.Text
      
              If ddlBaudRate.Text <> String.Empty Then
                  oGsmModem.BaudRate = Convert.ToInt32(ddlBaudRate.Text)
              End If
      
              If ddlDataBit.Text <> String.Empty Then
                  oGsmModem.DataBits = Convert.ToInt32(ddlDataBit.Text)
              End If
      
              If ddlStopBit.Text <> String.Empty Then
                  Select Case ddlStopBit.Text
                      Case "1"
                          oGsmModem.StopBits = Common.EnumStopBits.One
                      Case "1.5"
                          oGsmModem.StopBits = Common.EnumStopBits.OnePointFive
                      Case "2"
                          oGsmModem.StopBits = Common.EnumStopBits.Two
                  End Select
              End If
      
              If ddlFlowControl.Text <> String.Empty Then
                  Select Case ddlFlowControl.Text
                      Case "None"
                          oGsmModem.FlowControl = Common.EnumFlowControl.None
                      Case "Hardware"
                          oGsmModem.FlowControl = Common.EnumFlowControl.RTS_CTS
                      Case "Xon/Xoff"
                          oGsmModem.FlowControl = Common.EnumFlowControl.Xon_Xoff
                  End Select
              End If
      
              Try
                  oGsmModem.Connect()
              Catch ex As Exception
                  Response.Write(ex.Message)
                  Return
              End Try
      
              Try
                  oGsmModem.NewMessageIndication = True
              Catch ex As Exception
      
              End Try
      
              btnSend.Enabled = True
              btnDisconnect.Enabled = True
              btnConnect.Enabled = False
      
              oGsmModem.AutoDeleteSentMessage = True
              Response.Write("Connected to phone successfully !")
          End Sub
      
          Protected Sub btnDisconnect_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDisconnect.Click
              Try
                  oGsmModem.Disconnect()
              Catch ex As Exception
                  Response.Write(ex.Message)
              End Try
      
              btnSend.Enabled = False
              btnDisconnect.Enabled = False
              btnConnect.Enabled = True
          End Sub
      
          Private Sub Initialize()
              ' Read from the phone book
              'Dim strContent As String
              'm_strPhoneBook = Application.StartupPath & "\" & PHONE_BOOK
              'If My.Computer.FileSystem.FileExists(m_strPhoneBook) Then
              '    strContent = My.Computer.FileSystem.ReadAllText(m_strPhoneBook)
              '    Dim lines() As String = strContent.Split(ControlChars.CrLf)
              '    Dim i As Integer
              '    For i = 0 To lines.Length - 1
              '        lstMobileNumber.Items.Add(lines(i))
              '    Next
              'End If
          End Sub
      
          Protected Sub btnSend_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSend.Click
              If txtMessage.Text.Trim = String.Empty Then
                  Response.Write("Message must not be empty !")
                  Return
              End If
      
              If StringUtils.IsUnicode(txtMessage.Text) Then
                  oGsmModem.Encoding = Common.EnumEncoding.Unicode_16Bit
              Else
                  oGsmModem.Encoding = Common.EnumEncoding.GSM_Default_7Bit
              End If
      
              For Each item As String In lstMobileNumber.Items.ToString
                  If item.Trim <> String.Empty Then
                      oGsmModem.SendSMSToOutbox(item.Trim, txtMessage.Text.Trim)
                  End If
              Next
      
              Response.Write("Message is queued for sending !")
          End Sub
      
          Private Sub oGsmModem_OutboxSMSSent(ByVal e As ATSMS.OutboxSMSSentEventArgs) Handles oGsmModem.OutboxSMSSent
              If e.ErrorCode > 0 Then
                  txtDelivaryReport.Text = txtDelivaryReport.Text & "Error sending message to " & e.DestinationNumber & ". " & e.ErrorDescription & ControlChars.CrLf
              Else
                  txtDelivaryReport.Text = txtDelivaryReport.Text & "Message is delivered to " & e.DestinationNumber & ControlChars.CrLf
              End If
          End Sub
      
      End Class
      I am able to connect to phone successfully. btnSend_click code is working properly. But I get e.errorcode=400 6 in oGsmModem_Outbo xSMSSent event after btnSend_click event.

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

      Please help me...

      Thanks in advance.
      Last edited by Frinavale; Apr 7 '10, 08:12 PM. Reason: Please post code in [code] ... [/code] tags. They make it easier for us to read your code. Added code tags.

      Comment

      • CroCrew
        Recognized Expert Contributor
        • Jan 2008
        • 564

        #4
        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~

        Comment

        Working...