Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

eMail via SMS gateway is sent, but not received

Tags:

c#

sms

I am trying to send a free SMS from a gmail account to an airtel mobile (in Karnataka) using a C# Windows application. The message is sent and I can see sent items, but it is not received by the mobile phone.

This is my code,

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);

I can send emaill successfully using this code but for sms not working

like image 735
smileever143 Avatar asked Feb 07 '12 05:02

smileever143


2 Answers

You have to activate this service on mentioned mobile number. If it is not activated then you will not receive SMS on mobile it require 49/- charges or something like that.

If not activate you can activate and give try again

like image 75
Nil23 Avatar answered Sep 19 '22 06:09

Nil23


One approach would be to send a text message with your gmail account

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);
                }
            }
        }

For a List of Sms Gateways check http://en.wikipedia.org/wiki/List_of_SMS_gateways

Note: When the recipent responds to the message the message will be sent to your gmail account...Great for backups Smile | :) And read How to send SMS to mobile using SMTP server in windows application?

like image 45
Mr.kto Avatar answered Sep 21 '22 06:09

Mr.kto