Friday, November 14, 2014

Email-SMS Coding

Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .style1
        {
            width: 150px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table style="width: 100%;">
            <tr>
                <td class="style1">
                    &nbsp;
                </td>
                <td>
                    &nbsp;
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td class="style1">
                    &nbsp; masg</td>
                <td>
                    &nbsp;
                    <asp:TextBox ID="txtemail" runat="server"></asp:TextBox>
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td class="style1">
                    &nbsp;
                    Mob. No.</td>
                <td>
                    &nbsp;
                    <asp:TextBox ID="txtMono" runat="server"></asp:TextBox>
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td class="style1">
                    &nbsp;</td>
                <td>
                    <asp:Button ID="btnemail" runat="server" onclick="btnemail_Click"
                        Text="Send Email" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <asp:Button ID="sms" runat="server" onclick="sms_Click" Text="Send SMS" />
                </td>
                <td>
                    &nbsp;</td>
            </tr>
        </table>
    </div>
    </form>
</body>

</html>


Default.asp.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;
using System.IO;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnemail_Click(object sender, EventArgs e)
    {
            var smtp = new System.Net.Mail.SmtpClient();
            {
                smtp.Host = "smtp.gmail.com";
                smtp.Port = 587;
                smtp.EnableSsl = true;
                smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                smtp.Credentials = new NetworkCredential("<yourEmailID>@gmail.com", "<your Password>");
                smtp.Timeout = 20000;
            }
            smtp.Send("abcd@gmail.com", txtemail.Text, "Friend REQUEST.", "<br> your mobile num. is : " + txtMono.Text);
            ScriptManager.RegisterStartupScript(this, this.GetType(), "alertmessage", "javascript:alert('* Successfuliy Send Mobile Num. in your EmailID...')", true);

    }
    protected void sms_Click(object sender, EventArgs e)
    {

        ////======================================//
        //// SMS Booking Confirm.
        ////======================================//
        ////string sms = " Mr./Mrs." + ds.Tables[0].Rows[0][5].ToString() + " Your Booking Request is Confirm. Your Requested type Number is " + ds.Tables[0].Rows[0][4].ToString() + ". ";
        ////string strUrl = "http://api.mVaayoo.com/mvaayooapi/MessageCompose?user=hit_patel_76@yahoo.com:hitpatel&senderID=TEST SMS&receipientno=" + ds.Tables[0].Rows[0][8].ToString() + "&dcs=0&msgtxt=" + sms + " &state=4";
        //string msg = "hi... Good morning..";
        //string strUrl = "http://api.mVaayoo.com/mvaayooapi/MessageCompose?user=<youracc>@yahoo.com:100420116024&senderID=TEST SMS&receipientno="+ txtMono.Text +"&msgtxt="+ msg +"&state=4";
        //WebRequest request = HttpWebRequest.Create(strUrl);
        //HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        //Stream s = (Stream)response.GetResponseStream();
        //StreamReader readStream = new StreamReader(s);
        //string dataString = readStream.ReadToEnd();
        //response.Close();
        //s.Close();
        //readStream.Close();

        ////======================================//
        try
        {

            send("7894561230", "34560", txtemail.Text, txtMono.Text);
            Response.Write("message send successfully......");
        }
        catch
        {
            Response.Write("Error Occured!!!");
        }
    }
    public void send(string uid, string password, string message, string no)
    {
        HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("http://ubaid.tk/sms/sms.aspx?uid=" + uid + "&pwd=" + password + "&msg=" + message + "&phone=" + no + "&provider=fullonsms");
        HttpWebResponse myResp = (HttpWebResponse)myReq.GetResponse();
        System.IO.StreamReader respStreamReader = new System.IO.StreamReader(myResp.GetResponseStream());
        string responseString = respStreamReader.ReadToEnd();
        respStreamReader.Close();
        myResp.Close();
    }

}

No comments:

Post a Comment

Demo for Repository Pattern in ASP.Net

----------------------------------------------------------- ----------------------------------------------------------- Repository Projec...