Tuesday, 7 July 2015

Enquiry Form Open Page Load and Send Email Using in Web Service,HtmlPage Using Asp.Net C# JQuery

Enquiry Form Open Page Load and Send Email Using in Web Service,HtmlPage

Enquiry Form Open Page Load - Email Send To Users  Using Web Service & HtmlPage.html  in JQuery,JavaScript With GoogleApis in Asp.Net C#(Without Using WebForm).

                             Download Coding
                                                 Download

                                      DEMO


                       HTML CODING(HtmlPage.html)

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Enquery Form Open Page Load and Send Email Using in Web Service,HtmlPage Using  Asp.Net C# JQuery</title>

    <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<style type="text/css">

.popup{
width100%;
margin0 auto;
displaynone;
positionfixed;
z-index101;
}
.bor{
min-width600px;
width600px;
min-height350px;
margin100px auto;
background#808080;
positionrelative;
z-index103;
padding10px;
border-radius5px;
}
.bor .clo{
floatright;
height35px;
left22px;
positionrelative;
top-25px;
width34px;
}
#drizz {
positionfixed;
width100%;
height100%;
background-color#FF9933;
displaynone;
}
</style>
<script type='text/javascript'>
    $(function () {
        var overlay = $('<div id="drizz"></div>');
        overlay.show();
        overlay.appendTo(document.body);
        $('.popup').show();
        $('.close').click(function () {
            $('.popup').hide();
            overlay.appendTo(document.body).remove();
            return false;
        });
        $('.clo').click(function () {
            $('.popup').hide();
            overlay.appendTo(document.body).remove();
            return false;
        });

    });
</script>

    <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/base/jquery-ui.css"
        rel="stylesheet" type="text/css"/>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script>
    <script>
        function SendMail() {
            $("#Button1").click(function () {
                $.ajax({
                    url: "WebService.asmx/MailSend",
                    data: "{ 'To': '" + $('input[id$=Text1]').val() +
                  "', 'Message': '" + $('input[id$=Text2]').val() + "' }",
                    dataType: "json",
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    success: function (data) {
                        if (data.d == 1) {
                            alert('Success');

                            $('.popup').hide();
                            overlay.appendTo(document.body).remove();
                            return false;
                        }
                      
                    }
                });
            });
        }
</script>  
</head>
<body>

    <div class='popup'>
<div class='bor'>
<img src='drop.gif' alt='quit' runat="server" class='clo'  id='x' />

     <table><tr><td>To</td><td>
    <input id="Text1" type="text" /></td></tr>
        <tr><td>Message</td><td>
    <input id="Text2" type="text" /></td></tr>
        <tr><td colspan="2">    
    <input id="Button1"  type="button"  onclick ="SendMail();" value="SEND MAIL"  /></td></tr>

    </table>
    <a href="" class='close'>Hide</a>
</div>
        </div> 
  
</body>

</html>

                           Web Service.asmx

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Net.Mail;

/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {  
    [WebMethod]
    public  int MailSend(string To, string Message)
    {      
        MailMessage Msg = new MailMessage();
        Msg.From = new MailAddress("SenderMail@gmail.com"); // Sender e-mail address.
        Msg.To.Add(To);// Recipient e-mail address.
        Msg.Subject = "Send Mail Using WebServices";
        Msg.Body = Message;
        Msg.IsBodyHtml = true;     
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp.gmail.com";
        smtp.Port = 587;
        smtp.Credentials = new System.Net.NetworkCredential("YourMailId@gmail.com""Password");
        smtp.EnableSsl = true;
        smtp.Send(Msg);
        return 1;      
    }
   
}






















0 comments:

Post a Comment