Do you know how to do an asmx web service and call it?
If you do then just write a piece of code inside a web method which sends the mail.Will post a sample mail sending code here.
This sample code uses Gmail's SMTP server to send emails, if you want to send using your own SMTP server then just chalne the smtp settings or else use the same code and chane the Username /password
I'm pretty new to asp.net and I need to use the "sending email with WebService"....
Whats the diference writing the code above in the asmx or in the aspx.cs??
Thanks!
You can access web services from other applications i.e. for application communication and can configure the way it communicates with others(the protocols / Data format).
In aspx i.e. web forms it's used for creating a website that people would be accessing and can respond to events.
fialbz
Member
255 Points
161 Posts
Sending email through Web-Service (asmx)
Jun 23, 2012 11:46 PM|LINK
Do you have an example how to setup sending email through Web-Service (asmx) using C# with ASP.NET 3.5?
Also please show the “web.config” file for mailSettings setup. Thanks.
nijhawan.sau...
All-Star
16394 Points
3170 Posts
Re: Sending email through Web-Service (asmx)
Jun 24, 2012 06:11 AM|LINK
Do you know how to do an asmx web service and call it?
If you do then just write a piece of code inside a web method which sends the mail.Will post a sample mail sending code here.
This sample code uses Gmail's SMTP server to send emails, if you want to send using your own SMTP server then just chalne the smtp settings or else use the same code and chane the Username /password
System.Net.Mail; //Include This NameSpace MailMessage MyMailMessage = new MailMessage(); MyMailMessage.From = new MailAddress("adbuaryuy@gmail.com"); MyMailMessage.To.Add("yearningpeeks@yahoo.com"); MyMailMessage.Subject = "Feedback Form"; MyMailMessage.IsBodyHtml = true; MyMailMessage.Body = "<table><tr><td>" + txtName.Text + txtEmail.Text + txtComments.Text + "</table></tr></td>"; SmtpClient SMTPServer = new SmtpClient("smtp.gmail.com"); SMTPServer.Port = 587; SMTPServer.Credentials = new System.Net.NetworkCredential("adbuaryuy@gmail.com", System.Configuration.ConfigurationSettings.AppSettings["pwd"].ToString()); SMTPServer.EnableSsl = true; try { SMTPServer.Send(MyMailMessage); Response.Redirect("Thankyou.aspx"); } catch (Exception ex) { } http://www.aspsnippets.com/Articles/Create-and-send-HTML-Formatted-Emails-in-ASP.Net-using-C-and-VB.Net.aspxfialbz
Member
255 Points
161 Posts
Re: Sending email through Web-Service (asmx)
Jun 24, 2012 01:10 PM|LINK
Can I use my free of charge gmail to send the email is like your example?
Can you show the setting "web.config" file?
Thanks.
fialbz
Member
255 Points
161 Posts
Re: Sending email through Web-Service (asmx)
Jun 25, 2012 01:07 PM|LINK
Can gmail free of charge account is used to send an email like in your example?
Can you show the setting "web.config" file?
Thanks.
nijhawan.sau...
All-Star
16394 Points
3170 Posts
Re: Sending email through Web-Service (asmx)
Jun 25, 2012 04:11 PM|LINK
Yes you can use it.With this code, you don't have to put any other details in web.config.
PabloAp
Member
2 Points
1 Post
Re: Sending email through Web-Service (asmx)
Feb 19, 2013 07:51 PM|LINK
Hi Saurabh
I'm pretty new to asp.net and I need to use the "sending email with WebService"....
Whats the diference writing the code above in the asmx or in the aspx.cs??
Thanks!
nijhawan.sau...
All-Star
16394 Points
3170 Posts
Re: Sending email through Web-Service (asmx)
Apr 17, 2013 06:29 PM|LINK
You can access web services from other applications i.e. for application communication and can configure the way it communicates with others(the protocols / Data format).
In aspx i.e. web forms it's used for creating a website that people would be accessing and can respond to events.