Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Send Email with html body

6 views
Skip to first unread message

anu b

unread,
Nov 6, 2008, 6:20:51 PM11/6/08
to
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(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]

sloan

unread,
Nov 6, 2008, 7:15:13 PM11/6/08
to
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" <anup...@gmail.com> wrote in message
news:91aebe6d-db6a-4201...@j40g2000prh.googlegroups.com...

anu b

unread,
Nov 6, 2008, 7:31:26 PM11/6/08
to
I didnt do multi posting....can u send me the link in which u answered
the question...i can not access it

sloan

unread,
Nov 6, 2008, 9:51:18 PM11/6/08
to

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/microsoft.public.dotnet.languages.csharp/browse_thread/thread/9620895d1ec69c49#


Here are the other multi posts that I saw:

http://groups.google.com/group/microsoft.public.dotnet.languages.vb/browse_thread/thread/1f52cce2c63451df#

http://groups.google.com/group/microsoft.public.dotnet.languages.vb/browse_thread/thread/3ed39f011fcbb502#


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" <anup...@gmail.com> wrote in message

news:67607b01-def7-42ae...@d42g2000prb.googlegroups.com...

0 new messages