Mouni Bonasu

Mouni Bonasu

  • NA
  • 6
  • 1.5k

I have to send mail from html page using webservice

Sep 23 2015 1:56 AM
function SendButton() {
alert("hiii");
var domain = location.host;
var serviceurl ="http://localhost:50200/Innovadect/Email.asmx/SendEmail";
var name= $("#Name").val();
var toMailId= $("#Email").val();
var message= $("#Message").val();
var companyname=$("#CompanyName").val();
var PhNo=$("#PhNo").val();
var ServiceCategory=$("#ServiceCategory").val();
var Country=$("#Country").val();
var message=$("#Message").val();
$.ajax({
url: serviceurl,
data: "{ 'Name': '" + name + "','CompanyName':'"+companyname+"','Email': '" + toMailId+ "','PhNo':'"+PhNo+"','ServiceCategory':'"+ServiceCategory+"','Country':'"+Country+"','Message': '" + message+ "'}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (data){
alert("Success");
},
error: function () {
alert("Error");
}
});
}
 
 
[WebMethod]
public void SendEmail(string Name,string CompanyName,string Email,string PhNo,string ServiceCategory,string Country,string Message) {
MailMessage MyMailMessage = new MailMessage();
MyMailMessage.From = new MailAddress("[email protected]");
MyMailMessage.To.Add("[email protected]");
MyMailMessage.Subject = "Feedback Form";
MyMailMessage.IsBodyHtml = true;
MyMailMessage.Body = "<table><tr><td>" + Name + "</td>" + " <td>" + CompanyName + "</td>" + " <td>" + Email + "</td>" + " <td>" + PhNo + "</td>" + " <td>" + ServiceCategory + "</td>" + " <td>" + Country + "</td>" + " <td>" + Message + "</td> </tr>/table>";
SmtpClient SMTPServer = new SmtpClient("smtp.gmail.com");
SMTPServer.Port = 587;
SMTPServer.Credentials = new System.Net.NetworkCredential("[email protected]","xxxxxxxx" );//System.Configuration.ConfigurationSettings.AppSettings["pwd"].ToString()
SMTPServer.EnableSsl = true;
try
{
SMTPServer.Send(MyMailMessage);
}
catch (Exception ex)
{
}
}
}
Above is the code which im using ,cannot able to send mail getting error msg everytime
 

Answers (4)