2012-02-07 178 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?

相關問題