Roman Pelepei gives smart answers on questions about C# .Net, ASP .Net, WPF and Silverlight programming with examples and source code.
пятница, 14 августа 2009 г.
How to utilize Google gmail server in your.NET Web & Windows Applications
It's true; gmail allows you to use their mail servers to send email from your applications. If you combine that with the ASP.NET System.Net.Mail.SmtpClient class, you are ready to use your free gmail account and server.
Here is the Google mail server info you need:
Mail Host: smtp.gmail.com
You can use this info to send email from any Web or Windows application:
How to use in ASP.NET Web Application:
·In your web.config file, Add the following configuration section:
·Now from any where in your ASP.NET web application, you can send email using System.Net.Mail.SmtpClient as follows:
SmtpClient mailClient = newSmtpClient();
mailClient.EnableSsl = true;
mailClient.Send(from, to, subject, body);
This is very useful in many ways, for example, when you want to get notified about certain events that happen on your site. In my other article: "Ever wanted to know when Google bot visits your site?" I utilize the code above to know when a certain visitor comes to my site, specifically in this case, Google's spider.
How to use in .NET Windows Application:
·From your Windows application, you will need to setup the Network Credentials. Here is the code: