locked
SMS Texting via VB.net w/o GSM modem RRS feed

  • Question

  • Hi,

    I have a VB.net (2010) application wherein I need to send notification of a machine's status to a smartphone via texting.

    I would like to do it directly thru a gateway from the phone carrier rather than GSM modem or other, and have found some sample code, but think that I am having trouble configuring the email SMPT properly, though no sure.  Here is the code.  I commented out all of the variables from the form and entered the text strings directly:

    ************************************

    Imports System
    Imports System.Net.Mail

    Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click

            ' Collect user input from the form and stow content into
            ' the objects member variables

            mTo = "##########@vtext.com"      'Trim(txtPhoneNumber.Text) & Trim(cboCarrier.SelectedItem.ToString())
            mFrom = "myemail@gmail.com"              'Trim(txtSender.Text)
            mSubject = "test"                                    'Trim(txtSubject.Text)
            mMailServer = "smtp.gmail.com"              'Trim(txtMailServer.Text)
            mMsg = "test text"                                   'Trim(txtMessage.Text)

            ' Within a try catch, format and send the message to
            ' the recipient.  Catch and handle any errors.
            Try

                Dim message As New MailMessage(mFrom, mTo, mSubject, mMsg)
                Dim mySmtpClient As New SmtpClient(mMailServer)
                mySmtpClient.Port = 465
                mySmtpClient.UseDefaultCredentials = True
                mySmtpClient.Send(message)

                MessageBox.Show("The mail message has been sent to " &
    message.To.ToString(), "Mail", MessageBoxButtons.OK,
    MessageBoxIcon.Information)

            Catch ex As FormatException

                MessageBox.Show(ex.StackTrace, ex.Message, MessageBoxButtons.OK,
    MessageBoxIcon.Error)

            Catch ex As SmtpException

                MessageBox.Show(ex.StackTrace, ex.Message, MessageBoxButtons.OK,
    MessageBoxIcon.Error)

            Catch ex As Exception

                MessageBox.Show(ex.StackTrace, ex.Message, MessageBoxButtons.OK,
    MessageBoxIcon.Error)

            End Try

        End Sub

    ***************************************

    I can't figure out why this will not work.  Several examples follow the same basic format.

    Here is the info for my gmail account:

    

    Any help would be so greatly appreciated.

    Thanks!

    • Moved by Marvin_Guo Friday, October 17, 2014 8:54 AM VB Related
    Thursday, October 16, 2014 8:51 PM

Answers

All replies