Saturday, December 09, 2006

Your Gmail Account as SMTP Server, ASP NET 2.0

It's gorgeous, when you don't lose time to configure SMTP Server for a simple test. You could use your Gmail Account, to do it.

I read this article before:
Configuring other mail clients
Sending Email with System.Net.Mail
How to use System.Net.Mail.SmtpClient via SSL and Authentication?

Well for accomplish that, first adjust your web.config...

<system.net>
<mailsettings>
<smtp>
<network host="smtp.gmail.com" port="587" username="youraccount@gmail.com" password="yourpassword" defaultcredentials="false">
</network>
</smtp>
</mailsettings>
</system.net>


You write a few lines...

MailMessage message = new MailMessage();

message.From = new MailAddress("sender@domain.com");
message.To.Add(new MailAddress("destination@domain.com"));
message.Subject = "The subject";
message.Body = "The content";

SmtpClient client = new SmtpClient();
client.EnableSsl = true;
client.Send(message);


And run it.

No comments:

Google