473,508 Members | 2,361 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Send email with html body using System.net.mail

Now i am sending email to my friend using session variable...

but my code is as below
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;
//page content includes html
mail.IsBodyHtml = true;
//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("<b>th is is bold text,
and
Viewable by those client that support html </b>", null, "text/html");
//mail.AlternateViews.Add(PlainView);
//mail.AlternateViews.Add(htmlView);
mail.Body = msgBody;
//mail.BodyEncoding = System.Text.Encoding.UTF8;
//mail.BodyEncoding.IsBrowserSave = true;
//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;
}
}
eventhogh i did mail.Isbodyhtml = true....

my email shows html tags in it i dont need that...how can i get that
do u hav any idea?
Nov 6 '08 #1
2 18156
First, do NOT MULTIPOST.

Etiquette is to CrossPost to one (or a few) germane newsgroups (The total #
of newsgroups should be a frugal number)

.......
Now your issue.

You can try getting the source code here:
http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!138.entry

Download the example. I am able to send html email through that code.

You should encapsulate your method better.
You have Session data being pulled from within your method. 8<

Go get the source code from my blog, and you will have an encapsulated
method.
Then use a different function to create the html you want to send.
Then call the method.

private string CreateHtml ( string absoluteLink , string msgBody )
{
return "<html><body>"+"<h3>Hi :"+msgBody+"</h3>"+"<br/>You
visited:"+absoluteLink +"</body></html>";
}

private void CollectInfoAndSendEmail()
{

string html = CreateHtml( " http: // www . yahoo .com " , "Billy" );
SendEmailFramework_1_1( GetSettings() , "me@ toyou.com" , "Message From
the System", html);

}

private EmailSmtpSettings GetSettings()
{
EmailSmtpSettings settings =
((EmailSmtpSettings)System.Configuration.Configura tionSettings.GetConfig(CONFIG_SECTION_NAME));
return settings;
}


//Change my methods signature:
SendEmailFramework_1_1( SmtpServerSettings serv , string toAddress , string
subjectLine , string htmlBody )


Encapsulate, and less-spaghetti'fy your code.


Note: SmtpServerSettings is my custom object available in the downloadable
sourcecode.


"anu b" <an*******@gmail.comwrote in message
news:f2**********************************@j40g2000 prh.googlegroups.com...
Now i am sending email to my friend using session variable...

but my code is as below
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;
//page content includes html
mail.IsBodyHtml = true;
//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("<b>th is is bold text,
and
Viewable by those client that support html </b>", null, "text/html");
//mail.AlternateViews.Add(PlainView);
//mail.AlternateViews.Add(htmlView);
mail.Body = msgBody;
//mail.BodyEncoding = System.Text.Encoding.UTF8;
//mail.BodyEncoding.IsBrowserSave = true;
//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;
}
}
eventhogh i did mail.Isbodyhtml = true....

my email shows html tags in it i dont need that...how can i get that
do u hav any idea?


Nov 7 '08 #2

PS
Utils.SendMailMessage(mail);

That code isn't available, so we have no idea what is happening in its
contents.


"sloan" <sl***@ipass.netwrote in message
news:ux**************@TK2MSFTNGP02.phx.gbl...
First, do NOT MULTIPOST.

Etiquette is to CrossPost to one (or a few) germane newsgroups (The total
# of newsgroups should be a frugal number)

......
Now your issue.

You can try getting the source code here:
http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!138.entry

Download the example. I am able to send html email through that code.

You should encapsulate your method better.
You have Session data being pulled from within your method. 8<

Go get the source code from my blog, and you will have an encapsulated
method.
Then use a different function to create the html you want to send.
Then call the method.

private string CreateHtml ( string absoluteLink , string msgBody )
{
return "<html><body>"+"<h3>Hi :"+msgBody+"</h3>"+"<br/>You
visited:"+absoluteLink +"</body></html>";
}

private void CollectInfoAndSendEmail()
{

string html = CreateHtml( " http: // www . yahoo .com " , "Billy" );
SendEmailFramework_1_1( GetSettings() , "me@ toyou.com" , "Message From
the System", html);

}

private EmailSmtpSettings GetSettings()
{
EmailSmtpSettings settings =
((EmailSmtpSettings)System.Configuration.Configura tionSettings.GetConfig(CONFIG_SECTION_NAME));
return settings;
}


//Change my methods signature:
SendEmailFramework_1_1( SmtpServerSettings serv , string toAddress ,
string subjectLine , string htmlBody )


Encapsulate, and less-spaghetti'fy your code.


Note: SmtpServerSettings is my custom object available in the
downloadable sourcecode.


"anu b" <an*******@gmail.comwrote in message
news:f2**********************************@j40g2000 prh.googlegroups.com...
>Now i am sending email to my friend using session variable...

but my code is as below
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;
//page content includes html
mail.IsBodyHtml = true;
//mail.BodyFormat = System.Web.Mail.MailFormat.Html;
// AlternateView PlainView =
AlternateView.CreateAlternateViewFromString("Th is is my Plain text
Content, Viewable by those client that dont support html", null,
"text/
Plain");
//AlternateView htmlView =
AlternateView.CreateAlternateViewFromString("<b>t his is bold text,
and
Viewable by those client that support html </b>", null, "text/html");
//mail.AlternateViews.Add(PlainView);
//mail.AlternateViews.Add(htmlView);
mail.Body = msgBody;
//mail.BodyEncoding = System.Text.Encoding.UTF8;
//mail.BodyEncoding.IsBrowserSave = true;
//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;
}
}
eventhogh i did mail.Isbodyhtml = true....

my email shows html tags in it i dont need that...how can i get that
do u hav any idea?



Nov 7 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1592
by: Michal | last post by:
Hi I need to connect to Exchange 5.5 from .Net Web Application and send email using user profile. I did it two years ago on ASP but now I have to migrate it to .Net. I can not find any...
1
5945
by: Mr T | last post by:
I know how to send email from Access and I know how to create a custom form in Outlook. but.... How do I put the email info from Access into the Outlook custom form ??? Dim MyDB As Database Dim...
3
2726
by: Aur_Ros | last post by:
I am showing a table in a web page, I need help to email this table, please any sugestion ....? thanks!!
1
3116
by: monyrajesh | last post by:
<%@LANGUAGE="VBSCRIPT"%> <% nam=request.Form("name") mail=request.Form("email") phoneres=request.Form("res") phonembl=request.Form("mobile") adrs=request.Form("address")...
4
2157
by: PleaseHelpMe | last post by:
Any1 can tell me how to go about sending email with attachment in vb programming code. I know SMTP is one option, but I can't seem to get it working. Any other suggestion?? Thanks in advance
0
2136
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 {
1
2661
by: sunraj | last post by:
With the Following Fields can Anybody Help me, How do I send email from ASP using SMTP Authentication <html> <head> <meta http-equiv="Content-Language" content="en-us"> <meta...
0
3430
by: ram1927 | last post by:
Here is my platform: .net framewrok 1.1 Windows Xp Propfessional MS Office 2007. Visual Studio 2003. Window based application. I did below mentioned steps: 1. Right click on C#...
0
7115
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...
0
7321
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,...
1
7036
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...
0
7489
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5624
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,...
0
4705
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1547
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 ...
0
414
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.