2012-02-07 198 views
8

我试图使用C#Windows应用程序将gmail帐户的免费短信发送至airtel移动(在卡纳塔克邦)。该消息已发送,我可以看到已发送的项目,但未被手机接收。通过短信网关发送电子邮件,但未收到

这是我的代码,

SmtpClient smtp = new SmtpClient(); 
smtp.Credentials = new NetworkCredential("[email protected]", "activedust");   
smtp.Port = 587; 
smtp.Host = "smtp.gmail.com"; 
smtp.EnableSsl = true; 
smtp.DeliveryMethod = SmtpDeliveryMethod.Network; 
MailMessage message = new MailMessage(); 

message.To.Add("[email protected]");//replace no with airtel mobile number in Karnataka 

message.From = new MailAddress("[email protected]", "App",System.Text.Encoding.UTF8); 
message.Body = "type your body"; 
message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure; 
smtp.send(message); 

我可以给emaill成功使用此代码,但对于短信不能正常工作

+0

尝试发送电子邮件到其他地方,以检查它是否实际收到为en电子邮件而不是短信 – 2012-02-07 07:37:16

+1

电子邮件到短信网关是可靠地提供邮件臭名昭着的糟糕。您很可能被运营商阻止或标记为垃圾邮件。 – 2012-02-08 09:45:55

+0

您不需要使用[smtp]的任何帐户(https://fr.wikipedia.org/wiki/Wikipédia:Oracle/semaine_43_2013#Envoyer_un_SMS_par_e-mail“只需查看会话示例;您无需了解法语为了它”)。 – user2284570 2013-12-29 13:17:20

回答

2

你必须激活提到的手机号码,这项服务。如果它没有被激活,那么你将不会在手机上收到短信,它需要49/- 收费或类似的东西。

如果没有激活,您可以激活并给予再试

2

一种方法是用您的Gmail帐户

using System.Net; 
using System.Net.Mail; 

public void SendTextMessage(string subject, string message, long telephoneNumer) 
     { 
      // login details for gmail acct. 
      const string sender = "[email protected]"; 
      const string password = "mypassword4gmailacct"; 

      // find the carriers sms gateway for the recipent. txt.att.net is for AT&T customers. 
      string carrierGateway = "txt.att.net"; 

      // this is the recipents number @ carrierGateway that gmail use to deliver message. 
      string recipent = string.Concat(new object[]{ 
      telephoneNumer, 
      '@', 
      carrierGateway 
      }); 

      // form the text message and send 
      using (MailMessage textMessage = new MailMessage(sender, recipent, subject, message)) 
      { 
       using (SmtpClient textMessageClient = new SmtpClient("smtp.gmail.com", 587)) 
       { 
        textMessageClient.UseDefaultCredentials = false; 
        textMessageClient.EnableSsl = true; 
        textMessageClient.Credentials = new NetworkCredential(sender, password); 
        textMessageClient.Send(textMessage); 
       } 
      } 
     } 

发送短信短信网关列表检查http://en.wikipedia.org/wiki/List_of_SMS_gateways

注意:当配方回复邮件时,邮件将发送到您的gmail帐户...非常适合备份:) 并阅读How to send SMS to mobile using SMTP server in windows application?