如何在Windows应用程序中使用SMTP服务器发送短信到手机? [英] How to send SMS to mobile using SMTP server in windows application?

查看:275
本文介绍了如何在Windows应用程序中使用SMTP服务器发送短信到手机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在使用C#开发一个Windows应用程序,其中我想根据一些条件向一些用户发送短信。我通过许多论坛帖子发送短信使用SMTP服务器,但没有一个使用我的全部。在 这个 我有一些线索通过Gmail SMTP发送短信,但不能正常工作,因为我认为它是运营商特定的(不确定)。

我的代码示例:

  try 
{
MailMessage message = new MailMessage );
message.To.Add(1568235685@sms.sancharnet.in);
message.From = new MailAddress(sameone@gmail.com); //见后面的笔记...
message.Body =你好吗?

SmtpClient smtp = new SmtpClient(smtp.gmail.com);
smtp.EnableSsl = true;
smtp.Port = 587;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential(someonet@gmail.com,密码);

smtp.Send(message);
MessageBox.Show(发送成功);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message,Error);
}

上面的代码没有给出任何异常或错误,但是我没有得到任何短信在我的号码以及。

所以,我想问的是有什么办法可以使用SMTP服务器将短信发送到任何运营商的手机号码?


解决方案

您必须发送到SMS网关。维基百科有一个列表SMS网关



例如,要发送到Sprint PCS号码,您将发送到number@messaging.sprintpcs.com,其中number是电话号码(即5551234567,或其他)。



I am developing a windows application using C#, in which i want to send SMS to some user based on some condition. i goes through the many forum post to "Send SMS using SMTP Server" but none of them use-full for me. In this i got some clue to send SMS through Gmail SMTP but not working as i think it is carrier specific (not sure).
My code sample :

try
{
    MailMessage message = new MailMessage();
    message.To.Add("1568235685@sms.sancharnet.in");
    message.From = new MailAddress("sameone@gmail.com"); //See the note afterwards...
    message.Body = "Hi, How r you ?";

    SmtpClient smtp = new SmtpClient("smtp.gmail.com");
    smtp.EnableSsl = true;
    smtp.Port = 587;
    smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
    smtp.Credentials = new NetworkCredential("someonet@gmail.com", "password");

    smtp.Send(message);
    MessageBox.Show("Message sent successfully");
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message, "Error");
}

above code not giving any exception or error but also i am not getting any sms on my number as well.

So, what i want to ask that is there any way to send SMS using SMTP server to the mobile number of any carrier?

解决方案

You have to send to the SMS gateway. It is provider specific.

Wikipedia has a List of SMS Gateways.

For example, to send to a Sprint PCS number you would send to number@messaging.sprintpcs.com, where number is the phone number (i.e. 5551234567, or whatever).

这篇关于如何在Windows应用程序中使用SMTP服务器发送短信到手机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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