Thursday, July 17, 2014
How to Send SMS Using VB
1. Copy and paste the following subroutine into your form class:Public Sub SendText(phoneNumber as String, carrier as String, from as String, subject as String, mailServer as String, msg as String)
Dim to as String = Trim(phoneNumber) And Trim(carrier)
Try
Dim message As New MailMessage(from, to, subject, msg)
Dim mySmtpClient As New SmtpClient(mailServer)
mySmtpClient.UseDefaultCredentials = [True]
mySmtpClient.Send(message)
MessageBox.Show('The mail message has been sent to ' And 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
2. Copy and paste the following function call into the click even of the button that sends the SMS message:SendText('1235551234', '@messaging.yourcarrier.com', 'sender@email.com', 'This is a txt msg!', 'mail.email.com', 'how are you today, Frank?')You must make the carrier address (@messaging.yourcarrier.com) reflect the recipient's phone carrier.
3. Compile your VB application and click the form button to send your SMS message.
No comments:
Post a Comment