2
Reply

want to send a sms alert on mobil on recieving a new email

swati

swati

Apr 13 2016 5:45 AM
476
Hi All ,
 
i was trying to send a sms alert on mobile when i receive a new email from my c sharp windows form application .  i am able to send and receive an email but with sms alert still not any luck . plz provide your valuable inputs , i am new to c sharp.here is the code snippet :
 
private void btnSend_Click(object sender, EventArgs e)
{

// mail
try
{

MailMessage mail = new MailMessage(txtFrom.Text, txtTo.Text, txtSubject.Text, mailBody.Text);
//smtpserver = eg. smtp.gmail.com or smtp.yahoo.com you can search it on google for any provider i.e. email provider
SmtpClient client = new SmtpClient(txtsmtpServer.Text); //587 is a port for gmail
client.Port = 587;
client.Credentials = new System.Net.NetworkCredential(txtUsername.Text, txtPassword.Text);
//port 587 allows you to enable ssl setting is mendatory for gmail smtp server
client.EnableSsl = true;
client.Send(mail);

//sms alert
WebClient smsClient = new WebClient();
string to = txtmobnumber.Text;
string Message = "You have a new email in your mailbox" + txtTo.Text + "from" + txtUsername.Text;

string baseurl = "http://api.clickatell.com/http/sendmsg?user= swati1621&password=NgBbGHSDREbGGg&api_id=3597344&to='" + to + "'&text='" + Message + "'";
smsClient.OpenRead(baseurl);


MessageBox.Show("mail sent successfully", "Success", MessageBoxButtons.OK);
MessageBox.Show("sms sent successfully");
}

catch (Exception ex)
{
MessageBox.Show(ex.Message);
}



Answers (2)