How to send long message using AT Commands, vb.Net - vb.net

strMessage = SplitSMS(_dtMessageQueue.Rows(0)("Response"), 155)
For i As Integer = 0 To strMessage.GetUpperBound(0)
Try
With SerialPort1
.Write("AT" & vbCrLf)
Threading.Thread.Sleep(2000)
.Write("AT+CMGF=1" & vbCrLf)
Threading.Thread.Sleep(2000)
.Write("AT+CMGS=" & Chr(34) & _dtMessageQueue.Rows(0)("MobileNo") & Chr(34) & vbCrLf)
.Write(strMessage(i) & Chr(26) & vbCrLf)
Threading.Thread.Sleep(3000)
End With
Catch ex As Exception
MsgBox(ex.Message)
End Try
Next
I have written the above code in order to send SMS from my vb.net application to a Mobile phone.
Is it possible to send the message without splitting message,
I want to send the message as one.

SMS length is limited to 160 seven-bit characters. It was subsequently codified into the SMPP signalling protocol that transmits SMS and is limited to precisely 140 bytes (or 1120 bits).
try reading this

Related

Format a string into an email Body Format

I am using this code to send an email on my code
in this below code subject and mail body we are getting form dataset and storing in a string .
i didn't have any concern regarding subject but when it comes to body i am facing issue like
for example in my mail body i am having three points i.e, three line
1.some text
2.some text
3.some text
after the mail is triggered my mail body is looking like
1.some text 2.sometex 3.sometext .
here is my piece of code
Try
Dim SmtpServer As New SmtpClient
Dim mail As New MailMessage
SmtpServer.Credentials = New Net.NetworkCredential()
SmtpServer.Port = 25
SmtpServer.Host = "email.host.com"
mail = New MailMessage
mail.From = New MailAddress("myemail#email.com")
mail.To.Add("otheremail#email.com")
mail.Subject = Subject
mailbody= "<html>" & " <body>" & "<p>" _
& String.Join("</p><p>", mailbody.Split({Environment.NewLine},
StringSplitOptions.None)) _
& " </p>" & "</body> " & " </html>"
mail.Body = mailbody
mail.IsBodyHtml=true
SmtpServer.Send(mail)
catch ex As Exception
MsgBox(ex.ToString)
End Try
is there any way where i can get the exact format .
Please check the below screen shot
After generating the mail still i ma getting the mail is lookin like this
Give this a go:
mailbody = _
"<html>" & " <body>" & "<p>" _
& String.Join("</p><p>", mailbody.Split({Environment.NewLine}, StringSplitOptions.None)) _
& " </p>" & "</body> " & " </html>"
The issue was that you were splitting the lines int he mailbody and we weren't closing your HTML tags properly.
You are trying to insert the "Enter" in HTML (that doesn't work) replace that by <br/>
You can also replace the "Environment.NewLine" by <br/>
Use <br/> in HTML to bring the text to the next line.

Multiple sms send in AT commands VB.NET

I'm trying to send many or bulk sms using AT Command. I try send all number inside the datagrid but only first number is sending.
this is my code
Dim sql As New MySqlDataAdapter("select StudentID, StudentName,StudentContact, DueDate FROM issue inner join student on student.StudentID = issue.Student ", conn)
Dim ds As New DataSet
sql.Fill(ds, 0)
For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
Dim wholenum As String
Dim wholesms As String
wholenum = ds.Tables(0).Rows(i).Item(2).ToString
wholesms = "Hello " & ds.Tables(0).Rows(i).Item(1).ToString & ", this is your Due Date " & ds.Tables(0).Rows(i).Item(3).ToString & " pls return it on your due date"
If SerialPort1.IsOpen Then
Try
With SerialPort1
.Write("AT" & vbCrLf)
.Write("AT+CMGF=1" & vbCrLf)
.Write("AT+CMGS=" & Chr(34) & wholenum & Chr(34) & vbCrLf)
.Write(wholesms & Chr(26))
MsgBox("Success sa SEND")
'update one
'Call ConnectDatabase()
'com = New MySqlCommand("UPDATE issue SET Sent='1' ", conn)
'com.ExecuteNonQuery()
'Call DisconnectDatabase()
End With
Catch ex As Exception
MsgBox("Bad Signal or No load")
End Try
Else
MsgBox("Pls insert a modem")
End If
I think the looping is working 'cuz it apppears the successful message of how many inside in the datagrid view. But it only send the first number.
You need to fix your AT command handling significantly. First of all you need to read and parse everything the modem sends back to you after sending a AT command line (which by the way should be terminated with just "\r" and not vbCrLf).
You should never start sending a new command line before you have received the Final result code. And for AT+CMGS specifically you should never send the sms payload before you have received the "\r\n >" prefix.
These issues are covered in this and this answer. But the very first thing you should to is to read all of the text in chapter 5 in the V.250 specification. It is a really important document when working with AT commands.

+CMS ERROR: 305 when sending SMS

i have a system that can send sms when setting a schedule to confirm their scheduled appointment, but there's an error +CMS ERROR : 305
'SMS
query = "SELECT * FROM schedule WHERE Phone_Number ='" & txtPhoneNumber.Text & "'"
cmd = New MySqlCommand(query, MySqlConn)
reader = cmd.ExecuteReader
'TIME DATE SMS
Dim date1, time1 As String
date1 = Val(frmViewSchedule.dtpDate.Text)
time1 = Val(frmViewSchedule.dtpTime.Text)
txtMessage.Text = sys_msg + "TIME: " + time1 + " DATE: " + date1
If reader.HasRows Then
reader.Read()
txtPhoneNumber.Text = reader.Item("Phone_Number")
With SerialPort1
.Write("at" & vbCrLf)
Threading.Thread.Sleep(1000)
.Write("at+cmgf=1" & vbCrLf)
Threading.Thread.Sleep(1000)
.Write("at+cmgs=" & Chr(34) & txtPhoneNumber.Text & Chr(34) & vbCrLf)
.Write(txtMessage.Text & Chr(26))
Threading.Thread.Sleep(1000)
MsgBox(rcvdata.ToString)
End With
End If
CMS ERROR 305 means Invalid Text Format
The AT command to get in Text Mode is AT+CMGF=1 And PDU encoding is AT+CMGF=0
In Text Mode, encoding of the text when sending a SMS is important too.
Standard GSM Encoding is AT+CSCS="GSM"
And to be on the safe side, start with at AT&F (Factory default configuration). You can issue an AT&F command at start of your session to overcome possible strange settings that may be stored in the modem.

VB.NET Database Retrieval

I have a VB.NET application that has instant messaging-like functionality with a database. It can retrieve the values just fine, but the problem is the formatting isnt coming out right. I want the format to be as follows:
Sender: Message
(so...)
David: Hey guys
What I've tried below doesn't get me the result I'm looking for, it just prints the sender at the top of the rich textbox in my application and the message at the bottom, does anyone have any ideas?
'-------------------Retreives the message-------------------------------------------------------------
Dim sqlStr As String = "SELECT * FROM dojodb.chats"
Dim chatcommand As New MySqlCommand(sqlStr, MysqlConn)
Dim rdr As MySqlDataReader = chatcommand.ExecuteReader()
Dim tbl As New DataTable
tbl.Load(rdr)
'-------For every row, print the message, skip a line, and add 1 so it goes to next msg-- ------
For i As Integer = 0 To tbl.Rows.Count - 1
rowIndex = i
strSender &= CStr(tbl.Rows(rowIndex)("Sender")) & vbNewLine
strMessage &= CStr(tbl.Rows(rowIndex)("Message")) & vbNewLine
strOutPut = strSender + ": " + strMessage
Next
txtGroupChat.Text = strOutPut
'Keeps the richtextbox scrolled to the bottom so that most recent msg is always shown
txtGroupChat.SelectionStart = txtGroupChat.Text.Length
txtGroupChat.ScrollToCaret()
strOutPut = "" 'clearing the string so that it does not print out duplicate info next time
strSender = ""
strMessage = ""
'-------------------------End Retrive---------------------------------------
I feel a bit embarrassed posting this, but...
strSender = CStr(tbl.Rows(rowIndex)("Sender")) & ": "
strMessage = CStr(tbl.Rows(rowIndex)("Message")) & vbNewLine
strOutPut &= strSender & strMessage
What do you think vbNewLine does? Also, be careful of &=

"Pinging" an email address using VB.Net coding

Is there a way in VB.Net to "Ping" an email address to see if that email is a real one that does not give any errors?
If yes, can you show what the VB.Net coding looks like to implement this?
I plan to use this in an app that requires the Customer email and it would be nice to validate it as the call taker enters it into a form before saving the Customer details.
Here is the code we are using to send an email promotion to all of the customers in our customer table:
Private Sub RibbonButtonSendTestEmail_Click(sender As System.Object, e As System.EventArgs) Handles RibbonButtonSendTestEmail.Click
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
Dim strSqlStatement As String = "Select CustomerName, Email " & _
"From Customers "
Using objSqlCommand As SqlCommand = New SqlCommand(strSqlStatement, ObjConnection)
With objSqlCommand
' Open the SqlConnection before executing the query.
'---------------------------------------------------
Cursor = Cursors.WaitCursor
ObjConnection.Open()
Dim objDataReader As SqlDataReader = .ExecuteReader()
' Go through all the customers and send out the promotion emails.
'----------------------------------------------------------------
If objDataReader.HasRows Then
SmtpServer.Host = TextBoxSMTPServer.Text
SmtpServer.Port = TextBoxPort.Text
If TextBoxUseSSL.Text = "Yes" Then
SmtpServer.EnableSsl = True
Else
SmtpServer.EnableSsl = False
End If
If TextBoxUseDefaultCredentials.Text = "Yes" Then
SmtpServer.UseDefaultCredentials = True
Else
SmtpServer.UseDefaultCredentials = False
End If
SmtpServer.Credentials = New Net.NetworkCredential(TextBoxUserName.Text, TextBoxPassword.Text)
While objDataReader.Read()
Try
mail.To.Add(objDataReader("Email").ToString)
mail.From = New MailAddress(TextBoxEmailFrom.Text)
mail.Subject = "Promotion: " & TextBoxID.Text
mail.Body = "Dear " & objDataReader("CustomerName") & "," & vbCrLf & vbCrLf & TextBoxPromotionBodyText.Text
SmtpServer.Send(mail)
Catch exSMTP As SmtpException
MessageBox.Show("Sorry, I could not send an email for: " & _
vbCrLf & objDataReader("CustomerName") & "." & vbCrLf & _
"Please make sure it is correct.", _
"Error")
Catch exFormat As FormatException
MessageBox.Show("Sorry, this customer's email is not properly formatted: " & _
vbCrLf & objDataReader("CustomerName") & "." & vbCrLf & _
"Please make sure it is correct.", _
"Error")
End Try
End While
LabelEmail.Text = "Sent email promotions to the customers."
End If
objDataReader.Close()
ObjConnection.Close()
Cursor = Cursors.Default
End With ' objSqlCommand
End Using ' objSqlCommand
End Sub
Yes it's perfectly possible:
1 DNS Lookup the MX records for the domain
There may be multiples, you can pick anyone, although technically the one with the lowest preference indicator is the prefered one.
2 TCP Connect to the mail server (port 25)
Say hello: HELO
Identify yourself: mail from:<test#example.com>
Say who you're writing to: rcpt to<testaddress#example.com>
At this point the server will reply with a response, you'll get an OK or a 550 error with a message (like: The email account that you tried to reach does not exist)
Disconnect and the message will be dropped.
But dude, you want the VB code to do this? You just need a DNS talking piece and TCP connection building piece (or likely there are some SMTP libraries out there that'll do all this for you - or provide you with inspiration to figure it out yourself). Don't forget you can probably find a C# code example that does it and use Visual Studio's conversion tool to switch it to VB.
Note
Many domains have black holes/catch alls... the former will accept any email address and just delete it if it's invalid, the latter will accept any email address and forward them to a central account (no guarantees as to what happens then... sell the sender's address to spammers?) In both cases you won't get the 550 message, so you can never be certain.
There most reliable way to do this is to send a test email and have the recipient verify receipt by clicking on a link, which you then read and mark the email as active.
You should do primitive checks on the syntax of the email using regular expressions, but beyond that the most reliable way to validate an email is to attempt delivery and confirm the receipt.