如何使用C#桌面应用程序发送SMS消息? [英] How do I send SMS messages using a C# desktop application?

查看:66
本文介绍了如何使用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);

                }

推荐答案

您永远不会成功使用SMTP发送短信。 SMTP用于发送电子邮件。仍然可以从C#代码发送短信。但是你需要一个短信服务提供商。我曾经和其中一个人合作过(我只是记不起它的名字)。我担心他们都得到报酬。
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.


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆