我正在尝试使用C#Windows应用程序从Gmail帐户向airtel mobile(在卡纳塔克邦)发送免费短信。邮件已发送,我可以看到已发送的邮件,但手机未收到该邮件。
这是我的代码,
SmtpClient smtp = new SmtpClient();
smtp.Credentials = new NetworkCredential("youraccount@gmail.com", "activedust");
smtp.Port = 587;
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
MailMessage message = new MailMessage();
message.To.Add("919845no@airtelkk.com");//replace no with airtel mobile number in Karnataka
message.From = new MailAddress("youraccount@gmail.com", "App",System.Text.Encoding.UTF8);
message.Body = "type your body";
message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
smtp.send(message);
我可以使用此代码成功发送电子邮件,但短信无效
答案 0 :(得分:2)
您必须在上述手机号码上激活此服务。如果它没有被激活,那么你将不会在手机上接收短信需要49 / - 费用或类似的东西。
如果未激活,您可以激活并再次尝试
答案 1 :(得分: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 = "me@gmail.com";
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);
}
}
}
对于Sms网关列表,请检查http://en.wikipedia.org/wiki/List_of_SMS_gateways
注意:当食谱响应消息时,消息将被发送到您的Gmail帐户...非常适合备份:) 并阅读How to send SMS to mobile using SMTP server in windows application?