473,583 Members | 3,413 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.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
email

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]

Nov 6 '08 #1
3 7235
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.publi c.dotnet.langua ges.csharp

"anu b" <an*******@gmai l.comwrote in message
news:91******** *************** ***********@j40 g2000prh.google groups.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.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
email

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]

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*******@gmai l.comwrote in message
news:67******** *************** ***********@d42 g2000prb.google groups.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
1870
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 email them their login information. How do you grab the info and than use that info and put it into an email to send? Here is my code thus far...
5
4402
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 image) into the body of the email. Any help would be greatly appreciated. -- Nate Heaton
6
11170
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 will include the code I originally used. I understand I should switch from CDONTS to CDO mail but after several sttempts I am finding a very hard...
5
2318
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 multi-part and not html/text as expected. The code i use is: mailmsg.To = "XXX@XXXX.com" mailmsg.Subject = "some subject string" mailmsg.Body = <-- an...
1
2151
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
5256
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
5626
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 support .asp,.aspx files, it supports PHP files, I'm searching in JavaScript ,but not found any matter, I'don't Know PHP.I'm having lot of...
2
2475
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
18162
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
1825
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 .= $this->body; and I get a blank email to send. I've stripped down the body file but there still seems to be a problem. I'm not sure where to look now. This is...
0
7824
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8176
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8321
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7931
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3816
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3841
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2331
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1426
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.