Hello,
How to Using jQuery to Send Email with Web Services in .net and how to write code for email send in web service?
Please help me.
Thanks in advance
Ankit Agarwal
Software Engineer
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Aug 21, 2013, 11:19 PM EDT
Refer to this link:
http://blog.image0.com/web-development/using-jquery-to-send-email-with-web-services/
Ankit AgarwalRank #4,422 · 344 reputationPosted Aug 21, 2013, 11:24 PM EDT
I need to Mail.asmx page of this content.
How to write email send code in web service?
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 21, 2013, 11:45 PM EDT
Create a web method for sending mail like this
using System.Net.Mail;
public void SendUserMail()
{
}
Regards,
Iftikar
arjun singh chouhan9 reputationPosted Aug 22, 2013, 12:25 AM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 22, 2013, 12:53 AM EDT
Regards,
Iftikar
Ankit AgarwalRank #4,422 · 344 reputationPosted Aug 22, 2013, 1:39 AM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 22, 2013, 1:46 AM EDT
Iftikar
Ankit AgarwalRank #4,422 · 344 reputationPosted Aug 22, 2013, 1:50 AM EDT
So, How can we do with this html?
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 22, 2013, 2:09 AM EDT
public bool SendUserMail(string name, string toMailId, string message)
{
}
then in your html
var name= $("#txtName").val();
var toMailId= $("#txtEmail").val();
var message= $("#txtMessage").val();
data: "{ 'name': '" + name + "','toMailId': '" + toMailId+ "','message': '" + message+ "' }",
if(result ==true)
{
alert('mail sent');
}
Regards,
Iftikar
Ankit AgarwalRank #4,422 · 344 reputationPosted Aug 22, 2013, 2:44 AM EDT
Name:- Ankit
Email:- [email protected]
Message:- Test
SEND
Suppose I clicked On SEND and then message send to another email id, It should not be send to my [email protected].
Msg sholud be send as it is like:-
Name:- Ankit
Email:- [email protected]
Message:- Test
I am confusing that, what is toMailID?, it should be static and from mailid and name should be enter by user.
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 22, 2013, 2:49 AM EDT
[WebMethod]
public bool SendUserMail(string name, string fromMailId, string message)
{
in your script
function SendMail() {
var name= $("#txtName").val();
var fromMailId= $("#txtEmail").val();
var message= $("#txtMessage").val();
data: "{ 'name': '" + name + "','fromMailId': '" + fromMailId+ "','message': '" + message+ "' }",
Iftikar
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Aug 22, 2013, 2:50 AM EDT
i am attaching a sample just check that.
Ankit AgarwalRank #4,422 · 344 reputationPosted Aug 22, 2013, 3:03 AM EDT
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Aug 22, 2013, 3:06 AM EDT
userNameandpasswordsettings refer to the credentials for connecting to the SMTP server. Make sure you don't confuse this with the username and password for thefromortoaddress, which is not relevant to the SMTP server.the sample is for gmail mailid to send mail to other
Ankit AgarwalRank #4,422 · 344 reputationPosted Aug 22, 2013, 3:16 AM EDT
Again error
I am using our smtp details.
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 22, 2013, 3:20 AM EDT
Regards,
Iftikar
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Aug 22, 2013, 3:20 AM EDT
Ankit AgarwalRank #4,422 · 344 reputationPosted Aug 22, 2013, 3:23 AM EDT
mailMessage.From = new MailAddress(frmMailId,name);
mailMessage.To.Add("my email id");
mailMessage.Subject = "Test Subject";
mailMessage.IsBodyHtml = true;
mailMessage.Body = message;
SmtpClient mailbox = new SmtpClient("my smtp");
mailbox.Port = my port number;
mailbox.Send(mailMessage);
return true;
my smtp is correct i checked.
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 22, 2013, 3:24 AM EDT
[WebMethod]
public bool SendUserMail(string name, string fromMailId, string message)
{
Regards,
Iftikar
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Aug 22, 2013, 3:25 AM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 22, 2013, 3:26 AM EDT
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress(frmMailId,name);
mailMessage.To.Add("my email id");
mailMessage.Subject = "Test Subject";
mailMessage.IsBodyHtml = true;
mailMessage.Body = message;
SmtpClient mailbox = new SmtpClient("my smtp");
mailbox.Port = my port number;
return true;
Regards,
Iftikar
Ankit AgarwalRank #4,422 · 344 reputationPosted Aug 22, 2013, 3:35 AM EDT
Here was an error coming.
when we write this code:-
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress(frmMailId,name);
mailMessage.To.Add("toEmailID");
mailMessage.Subject = "Test Subject";
mailMessage.IsBodyHtml = true;
mailMessage.Body = message;
SmtpClient mailbox = new SmtpClient("My smtp");
mailbox.Send(mailMessage);
return true;
My SMTP is Correct.
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Aug 22, 2013, 3:47 AM EDT
Ankit AgarwalRank #4,422 · 344 reputationPosted Aug 22, 2013, 3:52 AM EDT
Here is an error coming with gmail smtp.
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 22, 2013, 3:53 AM EDT
Regards,
Iftikar
Ankit AgarwalRank #4,422 · 344 reputationPosted Aug 22, 2013, 3:58 AM EDT
Can it be reason for my error?
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Aug 22, 2013, 4:00 AM EDT
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress(frmMailId,name);
mailMessage.To.Add("my email id");
mailMessage.Subject = "Test Subject";
mailMessage.IsBodyHtml = true;
mailMessage.Body = message;
SmtpClient mailbox = new SmtpClient("smtp.gmail.com");
mailbox.Port = 587;
mailbox.Credentials = new NetworkCredential("your user id", "your password");
SmtpServer.EnableSsl = true;
mailbox.Send(mailMessage);
return true;
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 22, 2013, 4:01 AM EDT
Regards,
Iftikar
Ankit AgarwalRank #4,422 · 344 reputationPosted Aug 22, 2013, 4:07 AM EDT
it's not coming in my code.
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Aug 22, 2013, 4:10 AM EDT
mailbox.EnableSsl = true;
Ankit AgarwalRank #4,422 · 344 reputationPosted Aug 22, 2013, 4:17 AM EDT
with gmail smtp.
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 22, 2013, 4:18 AM EDT
Regards,
Iftikar
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Aug 22, 2013, 4:22 AM EDT
Happy coding.........
Ankit AgarwalRank #4,422 · 344 reputationPosted Aug 22, 2013, 4:28 AM EDT
now i will apply of this web service in my html form.
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Aug 22, 2013, 4:36 AM EDT
if you are doing it in Asp .net. i attached a sample above post just check that. if any problem reply.
Ankit AgarwalRank #4,422 · 344 reputationPosted Aug 22, 2013, 4:55 AM EDT
with my html code:-
but it's not running sucessfully.
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 22, 2013, 7:13 AM EDT
var serviceurl =location.protocol + "//" + domain + "Website/SendingMailWebService.asmx/SendUserMail";
to
var serviceurl =location.protocol + "//" + domain + "/Website/SendingMailWebService.asmx/SendUserMail";
Regards,
Iftikar
Ankit AgarwalRank #4,422 · 344 reputationPosted Aug 22, 2013, 10:21 PM EDT
var serviceurl =location.protocol + "//" + domain + "/Website/SendingMailWebService.asmx/SendUserMail";
my mail did not send.
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 22, 2013, 10:23 PM EDT
Regards,
Iftikar
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Aug 22, 2013, 10:25 PM EDT
is your service is inside the website or you created it separately.
Ankit AgarwalRank #4,422 · 344 reputationPosted Aug 22, 2013, 10:28 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 22, 2013, 10:29 PM EDT
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Aug 22, 2013, 10:59 PM EDT
I am attaching the Working code in Html page with jQuery and webservice to send mail. just download it and open it in visual studio. Run the Html page and check.
nitesh bagdi2 reputationPosted May 4, 2014, 10:18 PM EDT
Error2Could not create type 'WebService'.C:\Users\admin\Downloads\jquerymailusingwebservice\JqueryAutoComplete\WebService.asmx1
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts