如何使用C#桌面应用程序发送SMS消息

如何使用C#桌面应用程序发送SMS消息

本文介绍了如何使用C#桌面应用程序发送SMS消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用C#桌面应用程序向手机发送短信。



但是它出错了:

at System.Net.MAil.SmtpClient.Send(MailMessage message)

at EnQApp.Mailer.button1_Click(Object sender,EventArgs e)

c:\ Users \ businesssupport\Documents\Visual Studio 2012 \Projects\EnQApp\Mailer.cs.line 251



请提供给我任何手机的免费短信网关。

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.

{

                // 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);

                }

推荐答案


这篇关于如何使用C#桌面应用程序发送SMS消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 22:01