Showing posts with label Sending HTML Email. Show all posts
Showing posts with label Sending HTML Email. Show all posts

Friday, June 06, 2008

Useing HTML tags in C# or VB.Net codebehind

Its simple to use HTML tags in Code behind and display in ASP.NET web pages....

Method 1:

in .cs page

string t = txtBody.Text;
MyEmailBody.InnerHtml = Server.HtmlDecode(t);

in .aspx page

<div id="MyEmailBody" runat="server"></div>

It may some times require to change the ValidateRequest="false".

Method 2:

we can use Literal controls, to view HTML tags in .aspx pages from code behind.

in . aspx page

<asp:Literal runat="server"></asp:Literal>

in .cs page

this.Controls.Add(new LiteralControl("<b>This is Bold</b>"));

Hope this helps you in using HTML tags in codebehind.

Sending HTML Emails using ASP.NET, C# with embedded images

Today I found these useful links that helps us to embed the images in the HTML emails we are sending using ASP.NET & C#.

Simple HTML Format emails::

private void SendClick() {
MailMessage mailMsg = new MailMessage();
try {
mailMsg.To = "";
mailMsg.From = "";
mailMsg.BodyFormat = MailFormat.Html;
mailMsg.Subject = "Statistics Report";
mailMsg.Body ="content";
SmtpMail.SmtpServer ="serverHost";
SmtpMail.Send(mailMsg);
}
catch (Exception ex) {
Response.Write(ex.Message);
}
}

You can download the example code of sending HTML emails using ASP.NET here...

http://www.asp101.com/Samples/email_html_aspx.asp

http://download.microsoft.com/download/d/f/c/dfc7a022-3426-4868-b23c-3818a6e54305/HtmlEmail.zip

Links to Embed Images in HTML Emails Using ASP.NET & C#

To have a basic idea of mailing with an embedded image or object from ASP.NET 2.0 using SMTP Client. You can visit the following links...

http://aspalliance.com/1354_Sending_HTML_Mail_with_Embedded_Image_in_NET.8

http://www.codeproject.com/kb/IP/EmailByjebarson.aspx

http://www.codeproject.com/KB/aspnet/inkrajesh.aspx