我有一個在Visual Basic中發送短信的完美方式。
使用AT命令。
AT-命令:被指示,通過它可以發送和接收短信, ,這是一個例子:
將消息發送
第一:
編寫代碼的頂部
Imports System.IO.Ports
Imports System.IO
其次:
Dim SerialPort As New System.IO.Ports.SerialPort()
Dim CR As String
三:公共類形式的編寫代碼
創建一個文本框(TextmsgTextBox)寫的短信,1和TextBox(MobileNumberTextBox)輸入手機號碼,和按鈕( SendBUT)發送消息。
並將此代碼寫入按鈕單擊事件。
If SerialPort.IsOpen Then
SerialPort.Close()
End If
SerialPort.PortName = COM4
SerialPort.BaudRate = 9600
SerialPort.Parity = Parity.None
SerialPort.StopBits = StopBits.One
SerialPort.DataBits = 8
SerialPort.Handshake = Handshake.RequestToSend
SerialPort.DtrEnable = True
SerialPort.RtsEnable = True
SerialPort.NewLine = vbCrLf
Dim message As String
message = MsgRichTextBox.Text
Try
SerialPort.Open()
Catch ex As Exception
MsgBox("The modem with the port '" & SerialPort.PortName & "'is not plugged in!!" & vbcrlf & "Please plug the modem and try again.")
End Try
If SerialPort.IsOpen() Then
SerialPort.Write("AT" & vbCrLf)
SerialPort.Write("AT+CMGF=1" & vbCrLf)
SerialPort.Write("AT+CMGS=" & Chr(34) & phoneNumBox.Text & Chr(34) & vbCrLf)
SerialPort.Write(message & Chr(26))
SentPicture.Visible = True
SentLabel.Visible = True
SentTimer.Start()
Else
MsgBox("Port '" & SerialPort.PortName & "' is not available!")
End If
你的問題標題說的短信,但你的代碼顯示電子郵件/ SMTP。 但是,我沒有在您的連接中看到任何端口提及,並且我似乎記得在特定端口上運行gmail smtp。 –
嗨,Allan,我想發送短信,我應該使用哪個端口號? – nandgate
@ AllanS.Hansen,可能你還沒有閱讀過有關.... http://www.wirelessdevnet.com/channels/java/features/simplewire/不是嗎? – gumuruh