Email Send in Web Service,HtmlPage Using Asp.Net C# JQuery

Email Send in Web Service,HtmlPage Using  Asp.Net C# JQuery

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)


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>

    <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');                         
                        }
                    }
                });
            });
        }
</script>  
 
</head>
<body>
    <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>
</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;      
    }
   
}



First - Add New HtmlPage.html Form  






Next - Add Input Button.Button From ToolBox






Next - Add - Web Service.asmx From Solution Explorer






Next - Add JQuery,GoogleApi  &  JQuery Function From WebService.asmx






Next - Add - NameSpace(using System.Net.Mail)Email Send Coding  in WebService.asmx  Input Call From HtmlPage.html







4 comments:

  1. if (data.d == 1) {... why data.d, what is the 'd'? thank you!

    ReplyDelete
  2. I am impressed in the design of your website. Excellent designing, Thank you so much.
    website design classes
    web designing classes in chennai

    ReplyDelete
  3. This is bad. Always answer 1, even if the send fails.

    ReplyDelete