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.Collecti ons.Generic;
//using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.W ebControls;
using BlogEngine.Core ;
using BlogEngine.Core .Web.Controls;
using System.Net.Mail ;
using System.Text.Reg ularExpressions ;
using System.Text;
public partial class EmailTemplate : BlogBasePage
{
private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
}
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}
private void InitializeCompo nent()
{
////this.cmdSend.Cl ick += new System.EventHan dler(this.cmdSe nd_Click);
this.btnSend.Cl ick += new EventHandler(bt nSend_Click);
this.Load += new System.EventHan dler(this.Page_ Load);
}
void btnSend_Click(o bject sender, EventArgs e)
{
//throw new NotImplementedE xception();
bool success = SendEmail(txtTo .Text);
lblStatus.Visib le = !success;
divThank.Visibl e = success;
}
private bool SendEmail(strin g 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(n ew
Guid(Session["Content"].ToString() ));
//Take the link for the main content page and add it to the content.
Use HTML breaks.
msgBody = page2.AbsoluteL ink + "<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(n ew
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(Blo gSettings.Insta nce.Email);
//This should add fields from the form for the user's name and thier
MailAddress ma = new MailAddress(thi s.txtTo.Text,
this.txtFriends Name.Text);
mail.To.Add(ma) ;
mail.Subject = page.Title;
//mail.BodyEncodi ng = Encoding.GetEnc oding("iso-8859-1");
//mail.BodyFormat = System.Web.Mail .MailFormat.Htm l;
// AlternateView PlainView =
AlternateView.C reateAlternateV iewFromString(" This is my Plain text
Content, Viewable by those client that dont support html", null, "text/
Plain");
AlternateView htmlView =
AlternateView.C reateAlternateV iewFromString(m sgBody, Encoding.ASCII,
"text/html");
htmlView.Transf erEncoding = System.Net.Mime .TransferEncodi ng.SevenBit;
//mail.BodyEncodi ng = Encoding.GetEnc oding("GB2312") ;
mail.BodyEncodi ng = System.Text.Enc oding.ASCII;
//page content includes html
mail.Body = msgBody;
mail.BodyEncodi ng = System.Text.Enc oding.ASCII;mai l.IsBodyHtml =
true;
//mail.AlternateV iews.Add(PlainV iew);
//mail.AlternateV iews.Add(htmlVi ew);
//mail.BodyEncodi ng = System.Text.Enc oding.GetEncodi ng("GB2312");
//mail.Body = msgBody;
Utils.SendMailM essage(mail);
}
return true;
}
catch (Exception ex)
{
if (User.Identity. IsAuthenticated )
{
if (ex.InnerExcept ion != null)
lblStatus.Text = ex.InnerExcepti on.Message;
else
lblStatus.Text = ex.Message;
}
return false;
}
}
#region ICallbackEventH andler Members
////private string _Callback;
//public string GetCallbackResu lt()
//{
// //return _Callback;
//}
public void RaiseCallbackEv ent(string eventArgument)
{
}
#endregion
}
Select Tags... SaveCancel
[Edit Tags]