Sending text messages using C#
I wanted to create a site that would notify me if something was wrong, or an exception happened that it didn’t know how to handle. I have always felt that text messages are more immediate than an email. An email could be sent an I may or may not check it within an hour. But a text message was right now. In the order of importance in communication, there is the email, the text message and the phone call. I wanted a way to notify myself in an immediate way, without getting a phone call at all hours of the night. This way I could prioritize the issues for myself. Could it wait till morning or would I actually have to get out of bed and work on the problem right now.
In a previous company I had worked for, I had just such a thing. This company abused email to put it lightly, but if they wanted to really get attention they would send a text message. they literally abused text messaging also, but to a less extent than email. When I did the research on sending text messages programmatic I discovered this to be much simpler and easier than I originally thought.
Most wireless companies offer some sort of email to text service. So it is just a matter of finding the right email address for the person you want to send the text message too. My carrier is Verizon and they have the vtext.com service. So I simply put my phone number in front of the @vtext.com and we are in business. Then it was just simply send the email the same way.
Here is the code:
1 2 3 4 5 6 7 8 9 10 11 12 | public void SendTextMessage() { MailMessage message = new MailMessage(); message.From = new MailAddress("anemailaddress@domain.com"); message.To.Add("myphonnumber@vtext.com"); message.Body = "this is a test email/text"; SmtpClient smtp = new SmtpClient("SMTPserverAddress"); smtp.Send(message); } |
The same can be done in VB. Pretty simple right?