470,810 Members | 915 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,810 developers. It's quick & easy.

Send Email with html body

Hii

I am using System.net.mail for sending email...

i need to send a webpage with its html content as my email
body .....for that i used mail.Isbodyhtml as true...but it is not
working for me

so pls help me....

my code is as below

using System;

using System.Collections.Generic;

//using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using BlogEngine.Core;

using BlogEngine.Core.Web.Controls;

using System.Net.Mail;

using System.Text.RegularExpressions;

using System.Text;
public partial class EmailTemplate : BlogBasePage

{

private void Page_Load(object sender, System.EventArgs e)
{

// Put user code to initialize the page here

}

override protected void OnInit(EventArgs e)
{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeComponent();

base.OnInit(e);
}

private void InitializeComponent()
{

////this.cmdSend.Click += new System.EventHandler(this.cmdSend_Click);

this.btnSend.Click += new EventHandler(btnSend_Click);
this.Load += new System.EventHandler(this.Page_Load);

}

void btnSend_Click(object sender, EventArgs e)
{

//throw new NotImplementedException();

bool success = SendEmail(txtTo.Text);
lblStatus.Visible = !success;

divThank.Visible = success;

}

private bool SendEmail(string email)
{

try

{

using (MailMessage mail = new MailMessage())
{

string msgBody="";
string message = "";

//Load the template page for the email template.

BlogEngine.Core.Page page2 = BlogEngine.Core.Page.GetPage(new
Guid(Session["Content"].ToString() ));
//Take the link for the main content page and add it to the content.
Use HTML breaks.

msgBody = page2.AbsoluteLink + "<br/>";msgBody += page2.Content + "<br/
>";

//Take the content for the email heading intro message. This is hard
coded guid for the virtual page in the admin we created for sending
the email

BlogEngine.Core.Page page = BlogEngine.Core.Page.GetPage(new
Guid("ff8f0685-9f6a-4758-855d-6018d9542963"));
message = page.Content;

// Add the 911 intro

msgBody = message + "<br/>" + msgBody;
//Email is from 911

mail.From = new MailAddress(BlogSettings.Instance.Email);
//This should add fields from the form for the user's name and thier
email

MailAddress ma = new MailAddress(this.txtTo.Text,
this.txtFriendsName.Text);
mail.To.Add(ma);

mail.Subject = page.Title;

//mail.BodyEncoding = Encoding.GetEncoding("iso-8859-1");

//mail.BodyFormat = System.Web.Mail.MailFormat.Html;

// AlternateView PlainView =
AlternateView.CreateAlternateViewFromString("This is my Plain text
Content, Viewable by those client that dont support html", null, "text/
Plain");

AlternateView htmlView =
AlternateView.CreateAlternateViewFromString(msgBod y, Encoding.ASCII,
"text/html");
htmlView.TransferEncoding = System.Net.Mime.TransferEncoding.SevenBit;

//mail.BodyEncoding = Encoding.GetEncoding("GB2312");

mail.BodyEncoding = System.Text.Encoding.ASCII;
//page content includes html

mail.Body = msgBody;

mail.BodyEncoding = System.Text.Encoding.ASCII;mail.IsBodyHtml =
true;
//mail.AlternateViews.Add(PlainView);

//mail.AlternateViews.Add(htmlView);


//mail.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312");

//mail.Body = msgBody;



Utils.SendMailMessage(mail);
}

return true;
}

catch (Exception ex)
{

if (User.Identity.IsAuthenticated)
{

if (ex.InnerException != null)
lblStatus.Text = ex.InnerException.Message;

else

lblStatus.Text = ex.Message;

}

return false;
}

}

#region ICallbackEventHandler Members
////private string _Callback;

//public string GetCallbackResult()

//{

// //return _Callback;

//}

public void RaiseCallbackEvent(string eventArgument)
{

}

#endregion

}

Select Tags... SaveCancel
[Edit Tags]

Nov 6 '08 #1
3 7055
Please DO NOT MULTI POST ........

Etiquette is to CrossPost to one (or a few) germane newsgroups (The total #
of newsgroups should be a frugal number)
I answered (one of) your multiposts in the csharp group.
microsoft.public.dotnet.languages.csharp

"anu b" <an*******@gmail.comwrote in message
news:91**********************************@j40g2000 prh.googlegroups.com...
Hii

I am using System.net.mail for sending email...

i need to send a webpage with its html content as my email
body .....for that i used mail.Isbodyhtml as true...but it is not
working for me

so pls help me....

my code is as below

using System;

using System.Collections.Generic;

//using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using BlogEngine.Core;

using BlogEngine.Core.Web.Controls;

using System.Net.Mail;

using System.Text.RegularExpressions;

using System.Text;
public partial class EmailTemplate : BlogBasePage

{

private void Page_Load(object sender, System.EventArgs e)
{

// Put user code to initialize the page here

}

override protected void OnInit(EventArgs e)
{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeComponent();

base.OnInit(e);
}

private void InitializeComponent()
{

////this.cmdSend.Click += new System.EventHandler(this.cmdSend_Click);

this.btnSend.Click += new EventHandler(btnSend_Click);
this.Load += new System.EventHandler(this.Page_Load);

}

void btnSend_Click(object sender, EventArgs e)
{

//throw new NotImplementedException();

bool success = SendEmail(txtTo.Text);
lblStatus.Visible = !success;

divThank.Visible = success;

}

private bool SendEmail(string email)
{

try

{

using (MailMessage mail = new MailMessage())
{

string msgBody="";
string message = "";

//Load the template page for the email template.

BlogEngine.Core.Page page2 = BlogEngine.Core.Page.GetPage(new
Guid(Session["Content"].ToString() ));
//Take the link for the main content page and add it to the content.
Use HTML breaks.

msgBody = page2.AbsoluteLink + "<br/>";msgBody += page2.Content + "<br/
>>";


//Take the content for the email heading intro message. This is hard
coded guid for the virtual page in the admin we created for sending
the email

BlogEngine.Core.Page page = BlogEngine.Core.Page.GetPage(new
Guid("ff8f0685-9f6a-4758-855d-6018d9542963"));
message = page.Content;

// Add the 911 intro

msgBody = message + "<br/>" + msgBody;
//Email is from 911

mail.From = new MailAddress(BlogSettings.Instance.Email);
//This should add fields from the form for the user's name and thier
email

MailAddress ma = new MailAddress(this.txtTo.Text,
this.txtFriendsName.Text);
mail.To.Add(ma);

mail.Subject = page.Title;

//mail.BodyEncoding = Encoding.GetEncoding("iso-8859-1");

//mail.BodyFormat = System.Web.Mail.MailFormat.Html;

// AlternateView PlainView =
AlternateView.CreateAlternateViewFromString("This is my Plain text
Content, Viewable by those client that dont support html", null, "text/
Plain");

AlternateView htmlView =
AlternateView.CreateAlternateViewFromString(msgBod y, Encoding.ASCII,
"text/html");
htmlView.TransferEncoding = System.Net.Mime.TransferEncoding.SevenBit;

//mail.BodyEncoding = Encoding.GetEncoding("GB2312");

mail.BodyEncoding = System.Text.Encoding.ASCII;
//page content includes html

mail.Body = msgBody;

mail.BodyEncoding = System.Text.Encoding.ASCII;mail.IsBodyHtml =
true;
//mail.AlternateViews.Add(PlainView);

//mail.AlternateViews.Add(htmlView);


//mail.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312");

//mail.Body = msgBody;



Utils.SendMailMessage(mail);
}

return true;
}

catch (Exception ex)
{

if (User.Identity.IsAuthenticated)
{

if (ex.InnerException != null)
lblStatus.Text = ex.InnerException.Message;

else

lblStatus.Text = ex.Message;

}

return false;
}

}

#region ICallbackEventHandler Members
////private string _Callback;

//public string GetCallbackResult()

//{

// //return _Callback;

//}

public void RaiseCallbackEvent(string eventArgument)
{

}

#endregion

}

Select Tags... SaveCancel
[Edit Tags]

Nov 7 '08 #2
I didnt do multi posting....can u send me the link in which u answered
the question...i can not access it
Nov 7 '08 #3

If you didn't multi post, then how can send you a link where the question is
answered?

.........

Here is the multi post, FYI...the one where I responded...............

http://groups.google.com/group/micro...0895d1ec69c49#
Here are the other multi posts that I saw:

http://groups.google.com/group/micro...2cce2c63451df#

http://groups.google.com/group/micro...39f011fcbb502#
Here are some definitions:
http://info.borland.com/newsgroups/ngglossary.html
Multipost - Many messages, all with the same content, each posted to a
different newsgroup.

"anu b" <an*******@gmail.comwrote in message
news:67**********************************@d42g2000 prb.googlegroups.com...
>I didnt do multi posting....can u send me the link in which u answered
the question...i can not access it

Nov 7 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by nate heaton | last post: by
5 posts views Thread by Yossi Naggar | last post: by
2 posts views Thread by David Lozzi | last post: by
2 posts views Thread by Malli mindwave | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.