Can I send SMS Messages from a C# Application?

2020-02-05 09:44发布

I'm looking to build a program that would allow me to send SMS messages directly from the C# Application. I intend to build an 'Automatic Appointment Reminder' system that would automatically send SMS messages to recipients' mobile phones notifying them of their upcoming appointment.

Could anyone advise on how I would implement this type of feature as I have no experience in 'Mobile Communications' and mobile connectivity with desktop applications.

My carrier is EE (If that helps?)

Any help would be greatly appreciated.

3条回答
祖国的老花朵
2楼-- · 2020-02-05 09:54

Twilio has a C# helper library that will let you do this.

Here's the code you'd need to send a text message with the library:

using System;
using Twilio;
class Example
{
  static void Main(string[] args)
  {
    // Find your Account Sid and Auth Token at twilio.com/user/account
    string AccountSid = "{{ account_sid }}";
    string AuthToken = "{{ auth_token }}";

    var twilio = new TwilioRestClient(AccountSid, AuthToken);
    var message = twilio.SendMessage("+14158141829", "+14159352345", "This text message was sent with code!");

    Console.WriteLine(message.Sid);
  }
}

Disclaimer: I work for Twilio.

查看更多
乱世女痞
3楼-- · 2020-02-05 09:56

Most major carriers offer an email to text service. The program can use email to send an SMS message. For example:

Send an email

var message = new MailMessage();
message.From = new MailAddress("sender@foo.bar.com");

message.To.Add(new MailAddress("5551234567@txt.att.net"));//See carrier destinations below
//message.To.Add(new MailAddress("5551234568@txt.att.net"));

//message.CC.Add(new MailAddress("carboncopy@foo.bar.com"));
message.Subject = "This is my subject";
message.Body = "This is the content";

var client = new SmtpClient();
client.Send(message);

Carrier destinations

  • ATT: Compose a new email and use the recipient's 10-digit wireless phone number, followed by @txt.att.net. For example, 5551234567@txt.att.net.
  • Verizon: Similarly, ##@vtext.com
  • Sprint: ##@messaging.sprintpcs.com
  • TMobile: ##@tmomail.net
  • Virgin Mobile: ##@vmobl.com
  • Nextel: ##@messaging.nextel.com
  • Boost: ##@myboostmobile.com
  • Alltel: ##@message.alltel.com
  • EE: ##@mms.ee.co.uk (might support send without reply-to)

Alternatives

  • There are vendors that provide SMS messaging service via an API
查看更多
叛逆
4楼-- · 2020-02-05 10:07

You can send sms through variety of ways

  • Using a GSM modem
  • Using web service
  • Using endpoints given by service the provider

You can understand the basic logic for each of the above points through the link provided below and try to achieve that in your code.

http://www.codeproject.com/Articles/19023/Sending-SMS-using-NET

You need to create an instance of the sms engine in your form constructor like this.

  public partial class Form1 : Form
    {
        SMSCOMMS SMSEngine;

        public Form1()
        {

                    SMSEngine = new SMSCOMMS("COM1");



            InitializeComponent();
            SMSEngine.Open();
        }

        private void button1_Click(object sender, EventArgs e)
        {
          SMSEngine.SendSMS("919888888888","THIS IS YOUR MESSAGE");
          SMSEngine.Close();
        }
    }
}
查看更多
登录 后发表回答