Search This Blog

January 30, 2009

How to Send email from ASP.NET

In the web.config file add the following configuration

<system.net>
<mailSettings>
<smtp from="yourmailid@domain.com">
<network host="localhost" port="25" />
</smtp>
</mailSettings>
</system.net>

In the ASP.NET code

try
{
System.Net.Mail.SmtpClient Client = new System.Net.Mail.SmtpClient();
Client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.PickupDirectoryFromIis;
Client.Send("Frommailid@domin.com", "tomailid@domain.com", "Mail Sumbjet", "Mail Body");
}
catch (Exception ex)
{
Response.Wrire(ex.Message.ToString());
}