473,287 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

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 7211
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kenshin | last post by:
Hey! I have another script where i pull all the information from the database and I want to send it to the person. What they do is they enter in their email, and if the email matches, than it will...
5
by: nate heaton | last post by:
I would like to do the following with C# in my asp.net app: Open the default email client of the user (just like a mailto: link would). Supply the subject line and put some HTML (including an...
6
by: DigitalRick | last post by:
I have been running CDONTS in my ASPpages to send emails to me sent from my guestbook. It had been working fine untill I upgraded to Server 2003 (I am also running Exchange 2003) all locally. I...
5
by: Yossi Naggar | last post by:
Hello to everyone, Does anybody know how to send html formatted messages with asp.net? I tried to send such messages with the code below but the content type is wrong. The content type is...
1
by: Miguel Dias Moura | last post by:
Hello, Can you help me out in making this work? What I want is as simple as sending form values to an email. The code I am using is the following:
2
by: David Lozzi | last post by:
Howdy, I'm new to .Net 2.0... Getting "System.Net.Mail.SmtpException: The operation has timed out" on this script at the smtpClient.Send(msg) line Dim msg As New MailMessage
2
by: Malli mindwave | last post by:
Hi, We are using the yahoowebHostiing service for my company website, In that one screen of the SendComments/FeedBack section is there, I'm basically dot.net develeoper ,but yahoowebhosting not...
2
by: kennykenn | last post by:
Hi, Ive producd code to send an email after capturing info off a form,it works fine locally but when i put it live it doesnt work! the code is stopin at 'msg.send' any ideas, here the code! ...
2
by: anu b | last post by:
Now i am sending email to my friend using session variable... but my code is as below private bool SendEmail(string email) { try
2
by: urbanedge | last post by:
I've just acquired a site and uploaded to godaddy and the email function won't work. I'm new to php and I'm not able to determine where the issue is. I've commented out $this->header .=...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.