Wednesday, April 29, 2009

Use email template and send email with ASP.NET

Sometimes you need to send the email with the formatted manner. Here I have created a sample application by which you can send mail with the html template.


Steps:


1. Created an Email Class library, where a SendMail has been created which contins the properties and functions to send the mail.


2. Created a Web Application “EmailApplication” and added the reference of Email Class library.


3. Create the Test.html page to send the formatted mail. With the $ sign you can set the values at the run time. For example if I need to set the title of the email then I used $Title in html page.


4. Set the following things in the web.config file



< key="SmtpServer" value="mail.mailserver.com">
< key="SiteUrl" value="www.mysite.com/default.aspx" />
< key="IsSend" value="Yes">
< key="SendMailBackground" value="Yes">
<system.net>
<mailSettings>
<smtp>
< host="mail.mailserver.com" port="25" username="" password="">
< / smtp >
< / mailSettings >
< / system.net >


Here SmptServer represent the SMTP Server name, SiteUrl represent the your site url , SendMailBackground specify whether the mail should be send by background or not and IsSend represent whether you want to send the mail or not. If you want to stop the mail send facility then you don’t need to change the code you just need to change the web.config file to set the value of IsSend to “No”.



5. To send the mail through the site I have created a UI as Default.aspx, where you have to specify the sender email address, subject, message and attached file.



Download:

No comments:

Post a Comment