I've been tasked with sending a text message in a program. I got it to send ok using Net.Mail and a list of email-endings by phone carrier, but the text on the phone is broken into 3 parts when received.
My code is as follows:
'Email Customer
Dim strTo As String = ""
If Customer.NotifyByEmail Then
strTo = Customer.Email
End If
If Customer.NotifyByText Then
If strTo <> "" Then
strTo &= "," & Customer.PhoneNumber & Customer.PhoneEmailEnding
Else
strTo = Customer.PhoneNumber & Customer.PhoneEmailEnding
End If
End If
If strTo <> "" Then
Using oMailMsg As New Net.Mail.MailMessage
Using SmtpMail As New System.Net.Mail.SmtpClient With {
.Host = "mail.server.com",
.Port = 587,
.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network,
.EnableSsl = True,
.Credentials = New System.Net.NetworkCredential("[email protected]", "#####")
}
Dim sFrom As New Net.Mail.MailAddress("[email protected]")
oMailMsg.From = sFrom
If strTo.Contains(","c) Then
Dim arMultiTo As String() = Strings.Split(strTo, ",")
For Each strCurTo As String In arMultiTo
Dim sTo As New Net.Mail.MailAddress(strCurTo.Trim)
oMailMsg.To.Add(sTo)
Next
Else
Dim sTo As New Net.Mail.MailAddress(strTo.Trim)
oMailMsg.To.Add(sTo)
End If
oMailMsg.Subject = "Your Surfboard Repair Has Been Picked Up"
'Build the message body (text only)
oMailMsg.IsBodyHtml = False
oMailMsg.Body = "This message is to notify you that the board you dropped off for repair has been picked up by the repairman. Your contact info has been passed on to them and they may contact you if they have questions about the repair."
SmtpMail.Send(oMailMsg)
oMailMsg.Dispose()
End Using
End Using
End If
And the text is received as:
1 of 3
FRM:[email protected]
SUBJ:Your Surfboard Repair Has Been Picked Up
MSG:This message is to notify you that the board you dropped
(Con't) 2 of 3
off for repair has been picked up by the repairman. Your contact info has been passed on to them and they may contact you if they have
(Con't) 3 of 3
questions about the repair.
This is quite confusing to read. It's all one text message... Is there something going on with the mail buffer that's splitting the message up as it sends? Is there a way to get this to send as one full message instead of 3 parts?
I've poked around the available options under MailMessage and SmptClient, but haven't found anything that looks like a buffer size. I already switched IsBodyHtml between true and false, this didn't change anything.
-Edit-
Modifying the message body to include HTML doesn't help either, the phone completely ignores the formatting, <br/>
doesn't even leave a space, and it it still getting broken up into 3 parts.
With help from Andrew and user246821 in their comments, I was able to determine that my problem wasn't in my code, or a missed step with sending the message. So if anyone wants to send a text message to a phone through an email my code works just fine, as long as you fill in the 10 digit phone number and correct email ending from the phone provider table.
The character limit is a limitation of the SMS platform, which is what my emails were sending to, however in the phone provider table most carriers support MMS now which is newer and doesn't have the same limits. So for now, if supported, I am using each phone provider's MMS email to send the text messages. If this part of our business expands later and we need to send more than short quick updates we will look into a paid service like Twillio or Constant Contact.