<style>
/*------------------POPUPS------------------------*/#fade
{
display: none;
background: #fff;
position: fixed;
left: 0;
top: 0;
z-index: 10;
width: 100%;
height: 100%;
opacity: .50;
z-index: 9999;
}
.popup_block
{
display: none;
background: #fff;
padding: 10px;
border: 5px solid #ddd;
float: left;
font-size: 1.2em;
position: fixed;
top: 50%;
left: 50%;
z-index: 99999;
-webkit-box-shadow: 0px 0px 20px #000;
-moz-box-shadow: 0px 0px 20px #000;
box-shadow: 0px 0px 20px #000;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
}
img.btn_close
{
float: right;
margin: -40px -40px 0 0;
}
.popup p
{
padding: 5px 10px;
margin: 5px 0;
}
/*--Making IE6 Understand Fixed Positioning--*/*html #fade
{
position: absolute;
}
*html .popup_block
{
position: absolute;
}
#fade
{
z-index: 0;
}
</style>
<script language="javascript" type="text/javascript" src="jquery_bundle/jquery-1.9.1.js"></script>
<script language="javascript" type="text/javascript">
jQuery.fn.EncHTML = function() {
return String(this.html())
.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/'/g, ''')
.replace(/</g, '<')
.replace(/>/g, '>');
};
function sendMail() {
popUp('80', 'divTaskPopup');
var message = "";
message = "<div> Hi i am -----------------------.";
message += "<table align='left' border='0' cellpadding='0' cellspacing='3' width='100%'> ";
message += " <tr> ";
message += "<td width='250' height='34' align='left' valign='top'>";
message += " Reason";
message += " </td>";
message += " <td width='313' align='left' valign='top'>";
message += " XXXXXXX";
message += "</td>";
message += "</tr>";
message += "<tr>";
message += "<td width='250' height='34' align='left' valign='top'>";
message += " Would you like to sing up in future ?";
message += "</td>";
message += "<td width='313' align='left' valign='top'>";
message += " XXXXXXX";
message += "</td>";
message += "</tr>";
message += "<tr>";
message += "<td width='250' height='120px' align='left' valign='top'>";
message += " Description";
message += "</td>";
message += "<td width='313' align='left' valign='top' colspan='3'>";
message += " XXXXXXX XX X X X XXXX X X X X XX X X X X X X X X X XX X X";
message += "</td>";
message += "</tr>";
message += "</table>";
message += "</div>";
//Encode HTML
var message = $(message).EncHTML();
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "webservice/remote_service.asmx/sendMailAnsService",
data: "{'message':'" + message + "'}",
dataType: "json",
async: true,
success: function(data) {
popUpClose();
},
error: function(result) {
alert("Error");
}
});
}
function popUp(width, popUpID) {
var popID = popUpID;
var popWidth = width;
//Fade in the Popup and add close button
$('#' + popID).fadeIn().css({ 'width': Number(popWidth) }).prepend('<a href="javascript:void(0)" class="close"><img src="../images/close_pop.png" class="btn_close" title="Close Window" alt="Close" onclick="popUpClose();" /></a>');
//Define margin for center alignment (vertical + horizontal)
var popMargTop = ($('#' + popID).height() + 80) / 2;
var popMargLeft = ($('#' + popID).width() + 80) / 2;
//Apply Margin to Popup
$('#' + popID).css({
'margin-top': -popMargTop,
'margin-left': -popMargLeft
});
//Fade in Background
$('body').append('<div id="fade"></div>');
//Add the fade layer to bottom of the body tag.
$('#fade').css({ 'filter': 'alpha(opacity=80)' }).fadeIn();
//Fade in the fade layer
return false;
}
function popUpClose() {
$('#fade , .popup_block').fadeOut(function() {
$('#fade, a.close').remove();
$('#headerMessage').fadeOut();
});
}
</script>
<form id="form1" runat="server">
<div>
<input type="button" value="send" onclick="sendMail();" />
</div>
<div id="divTaskPopup" class="popup_block">
<div align="center">
<img src="http://sierrafire.cr.usgs.gov/images/loading.gif" style="height: 50px;
width: 50px" />
</div>
</div>
</form>
------remote_service
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;
using System.Web.Script.Serialization;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class remote_service : System.Web.Services.WebService
{
public remote_service()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public IList<string> sendMailAnsService(string message)
{
IList<string> result = new List<string>();
//Decode html
message = Server.HtmlDecode(message);
string strSenderMailId = "xxxxxx@xxxx.com";
string strSenderMailPassword = "xxxxxxxxxx";
string strMailFrom = "xxxxxxxxxx";
string strSmtpClient = "smtp.gmail.com";
int strSmtpPort = 587;
int r = sendMail.sendMailHandler(strSenderMailId, strSenderMailPassword, strMailFrom, strSmtpClient, strSmtpPort, "xxxxxxxxx@gmail.com", message, "testMail");
result.Add(r.ToString());
return result;
}
}
---------sendMailHandler
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
public class sendMail
{
public sendMail()
{
}
public static int sendMailHandler(string strSenderMailId, string strSenderMailPassword, string strMailFrom, string strSmtpClient, int strSmtpPort, string sendTo, string strMessage, string strSubject)
{
try
{
string emailID = strSenderMailId;
string password = strSenderMailPassword;
System.Net.Mail.MailMessage myMail = new System.Net.Mail.MailMessage();
System.Net.NetworkCredential cred = new System.Net.NetworkCredential(emailID, password);
myMail.To.Add(sendTo);
myMail.Subject = strSubject;
myMail.From = new System.Net.Mail.MailAddress(strMailFrom);
myMail.IsBodyHtml = true;
myMail.Body = strMessage;
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(strSmtpClient);
smtp.UseDefaultCredentials = false;
smtp.Credentials = cred;
smtp.EnableSsl = true;
smtp.Port = strSmtpPort;
smtp.Send(myMail);
return 1;
}
catch
{
return 0;
}
}
}
/*------------------POPUPS------------------------*/#fade
{
display: none;
background: #fff;
position: fixed;
left: 0;
top: 0;
z-index: 10;
width: 100%;
height: 100%;
opacity: .50;
z-index: 9999;
}
.popup_block
{
display: none;
background: #fff;
padding: 10px;
border: 5px solid #ddd;
float: left;
font-size: 1.2em;
position: fixed;
top: 50%;
left: 50%;
z-index: 99999;
-webkit-box-shadow: 0px 0px 20px #000;
-moz-box-shadow: 0px 0px 20px #000;
box-shadow: 0px 0px 20px #000;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
}
img.btn_close
{
float: right;
margin: -40px -40px 0 0;
}
.popup p
{
padding: 5px 10px;
margin: 5px 0;
}
/*--Making IE6 Understand Fixed Positioning--*/*html #fade
{
position: absolute;
}
*html .popup_block
{
position: absolute;
}
#fade
{
z-index: 0;
}
</style>
<script language="javascript" type="text/javascript" src="jquery_bundle/jquery-1.9.1.js"></script>
<script language="javascript" type="text/javascript">
jQuery.fn.EncHTML = function() {
return String(this.html())
.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/'/g, ''')
.replace(/</g, '<')
.replace(/>/g, '>');
};
function sendMail() {
popUp('80', 'divTaskPopup');
var message = "";
message = "<div> Hi i am -----------------------.";
message += "<table align='left' border='0' cellpadding='0' cellspacing='3' width='100%'> ";
message += " <tr> ";
message += "<td width='250' height='34' align='left' valign='top'>";
message += " Reason";
message += " </td>";
message += " <td width='313' align='left' valign='top'>";
message += " XXXXXXX";
message += "</td>";
message += "</tr>";
message += "<tr>";
message += "<td width='250' height='34' align='left' valign='top'>";
message += " Would you like to sing up in future ?";
message += "</td>";
message += "<td width='313' align='left' valign='top'>";
message += " XXXXXXX";
message += "</td>";
message += "</tr>";
message += "<tr>";
message += "<td width='250' height='120px' align='left' valign='top'>";
message += " Description";
message += "</td>";
message += "<td width='313' align='left' valign='top' colspan='3'>";
message += " XXXXXXX XX X X X XXXX X X X X XX X X X X X X X X X XX X X";
message += "</td>";
message += "</tr>";
message += "</table>";
message += "</div>";
//Encode HTML
var message = $(message).EncHTML();
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "webservice/remote_service.asmx/sendMailAnsService",
data: "{'message':'" + message + "'}",
dataType: "json",
async: true,
success: function(data) {
popUpClose();
},
error: function(result) {
alert("Error");
}
});
}
function popUp(width, popUpID) {
var popID = popUpID;
var popWidth = width;
//Fade in the Popup and add close button
$('#' + popID).fadeIn().css({ 'width': Number(popWidth) }).prepend('<a href="javascript:void(0)" class="close"><img src="../images/close_pop.png" class="btn_close" title="Close Window" alt="Close" onclick="popUpClose();" /></a>');
//Define margin for center alignment (vertical + horizontal)
var popMargTop = ($('#' + popID).height() + 80) / 2;
var popMargLeft = ($('#' + popID).width() + 80) / 2;
//Apply Margin to Popup
$('#' + popID).css({
'margin-top': -popMargTop,
'margin-left': -popMargLeft
});
//Fade in Background
$('body').append('<div id="fade"></div>');
//Add the fade layer to bottom of the body tag.
$('#fade').css({ 'filter': 'alpha(opacity=80)' }).fadeIn();
//Fade in the fade layer
return false;
}
function popUpClose() {
$('#fade , .popup_block').fadeOut(function() {
$('#fade, a.close').remove();
$('#headerMessage').fadeOut();
});
}
</script>
<form id="form1" runat="server">
<div>
<input type="button" value="send" onclick="sendMail();" />
</div>
<div id="divTaskPopup" class="popup_block">
<div align="center">
<img src="http://sierrafire.cr.usgs.gov/images/loading.gif" style="height: 50px;
width: 50px" />
</div>
</div>
</form>
------remote_service
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;
using System.Web.Script.Serialization;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class remote_service : System.Web.Services.WebService
{
public remote_service()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public IList<string> sendMailAnsService(string message)
{
IList<string> result = new List<string>();
//Decode html
message = Server.HtmlDecode(message);
string strSenderMailId = "xxxxxx@xxxx.com";
string strSenderMailPassword = "xxxxxxxxxx";
string strMailFrom = "xxxxxxxxxx";
string strSmtpClient = "smtp.gmail.com";
int strSmtpPort = 587;
int r = sendMail.sendMailHandler(strSenderMailId, strSenderMailPassword, strMailFrom, strSmtpClient, strSmtpPort, "xxxxxxxxx@gmail.com", message, "testMail");
result.Add(r.ToString());
return result;
}
}
---------sendMailHandler
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
public class sendMail
{
public sendMail()
{
}
public static int sendMailHandler(string strSenderMailId, string strSenderMailPassword, string strMailFrom, string strSmtpClient, int strSmtpPort, string sendTo, string strMessage, string strSubject)
{
try
{
string emailID = strSenderMailId;
string password = strSenderMailPassword;
System.Net.Mail.MailMessage myMail = new System.Net.Mail.MailMessage();
System.Net.NetworkCredential cred = new System.Net.NetworkCredential(emailID, password);
myMail.To.Add(sendTo);
myMail.Subject = strSubject;
myMail.From = new System.Net.Mail.MailAddress(strMailFrom);
myMail.IsBodyHtml = true;
myMail.Body = strMessage;
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(strSmtpClient);
smtp.UseDefaultCredentials = false;
smtp.Credentials = cred;
smtp.EnableSsl = true;
smtp.Port = strSmtpPort;
smtp.Send(myMail);
return 1;
}
catch
{
return 0;
}
}
}
No comments:
Post a Comment