A
anu b
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.
//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(msgBody, 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]
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 + said:
//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
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(msgBody, 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]