Click here to Skip to main content
15,893,663 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
I want to send SMS to a mobile phone using a C# desktop application.

But it gives an error saying:
at System.Net.MAil.SmtpClient.Send(MailMessage message)
at EnQApp.Mailer.button1_Click(Object sender, EventArgs e) in
c:\Users\businesssupport\Documents\Visual Studio 2012\Projects\EnQApp\Mailer.cs.line 251

Please, provide me with a free SMS gateway for any mobile phone.
C#
{

                // Collect user input from the form and stow content into

                // the objects member variables
                string tb1, tb2;
                tb1 = textBox1.Text;
                tb2 = comboBox1.SelectedItem.ToString();

                mTo1 = tb1.Trim() + tb2.Trim();

                mFrom = (textBox2.Text).Trim();

                mSubject = (textBox3.Text).Trim();

                mMailServer = (textBox4.Text).Trim();

                mMsg = (textBox5.Text).Trim();

                // Within a try catch, format and send the message to

                // the recipient.  Catch and handle any errors.

                try
                {

                    MailMessage message = new MailMessage(mFrom, mTo1, mSubject, mMsg);

                    SmtpClient mySmtpClient = new SmtpClient(mMailServer);

                    mySmtpClient.UseDefaultCredentials = true;

                    mySmtpClient.Send(message);

                    MessageBox.Show("Message Sent");

                }

                catch (FormatException ex)
                {

                    MessageBox.Show(ex.StackTrace, ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);

                }

                catch (SmtpException ex)
                {

                    MessageBox.Show(ex.StackTrace, ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);

                }

                catch (Exception ex)
                {

                    MessageBox.Show(ex.StackTrace, ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);

                }
Posted
Updated 17-Feb-15 21:53pm
v4
Comments
Zoltán Zörgő 7-Feb-15 2:17am    
Please provide me free beer. Nobody will provide you gateway, but anybody - including you, can search and find one if there is any in your region. Do you know google? Use it! Be aware, that SMS and SMTP have nothig to do with eachother - and few SMS gateways are providing SMTP interface...
Hemas Ilearn 7-Feb-15 2:40am    
yeah i did, yeap i know google.. but i couldn't find any
Mohammad Reza Valadkhani 7-Feb-15 10:09am    
i don't understand your code ! are you kidding ! the best way for you to send SMS from your desktop application if don't want to provide any sms gateway is GSM Modem
try to use GSM modem and connect to it using serial port and then send SMS by your application using serial interface!
Mamad Dark 11-Feb-15 9:11am    
you want to send a sms but you are using a mail server! (?)

1 solution

You will never succeed sending SMS using SMTP. SMTP is meant for e-mails. Still it's possible to send SMS from C# code. But you're going to need a SMS service provider. I used to work with one of them (I just don't remember its name). I'm afraid they're all paid.
 
Share this answer
 
Comments
Ravi Bhavnani 18-Feb-15 11:06am    
>You will never succeed sending SMS using SMTP.
Unless you use an email to SMS service. :)

/ravi

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900