473,382 Members | 1,421 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,382 software developers and data experts.

Formating email using C#

I'm trying to send an email from a Form. Here's what I have so far:

MailMessage mail = new MailMessage();
mail.To = "me@mycompany.com";
mail.From = "yo*@yourcompany.com";
mail.Subject = "this is a test email.";
mail.Body = "Line 1";
mail.Body += "Line 2";
mail.Body += "Line 3";
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate","1"); //basic authentication mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "my_username_here"); //set your username here mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "super_secret"); //set your password here SmtpMail.SmtpServer = "mail.mycompany.com"; //your real server goes here SmtpMail.Send( mail );The example is from here:http://systemwebmail.com/faq/3.8.aspxThe email sends and arrives successfully, however, I need to format themessage. I would like Line 1, Line 2, and Line 3 to be separate paragraphs.Any ideas how to do this?I have searched and found this:Carriage return character (U+000D)Line feed character (U+000A)Carriage return character (U+000D) followed by line feed character (U+000A)Line separator character (U+2028) Paragraph separator character (U+2029)But I don't know if this is what I'm looking for or how to use it.Thanks in advance,Scott Natwick

Nov 18 '05 #1
6 8323
Set MailFormat to a "1", which is HTML format. Then you can insert regular
HTML for formatting in your Body.

"Scott Natwick" <no****@yahoo.com> wrote in message
news:gs********************@comcast.com...
I'm trying to send an email from a Form. Here's what I have so far:

MailMessage mail = new MailMessage();
mail.To = "me@mycompany.com";
mail.From = "yo*@yourcompany.com";
mail.Subject = "this is a test email.";
mail.Body = "Line 1";
mail.Body += "Line 2";
mail.Body += "Line 3";
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenti
cate","1"); //basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername
", "my_username_here"); //set your username here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword
", "super_secret"); //set your password here SmtpMail.SmtpServer =
"mail.mycompany.com"; //your real server goes here SmtpMail.Send(
mail );The example is from here:http://systemwebmail.com/faq/3.8.aspxThe
email sends and arrives successfully, however, I need to format themessage.
I would like Line 1, Line 2, and Line 3 to be separate paragraphs.Any ideas
how to do this?I have searched and found this:Carriage return character
(U+000D)Line feed character (U+000A)Carriage return character (U+000D)
followed by line feed character (U+000A)Line separator character (U+2028)
Paragraph separator character (U+2029)But I don't know if this is what I'm
looking for or how to use it.Thanks in advance,Scott Natwick

Nov 18 '05 #2
I like your suggestion.

I added this code:
mail.BodyFormat = MailFormat.Html;
mail.Body = "<html><body>Testing 123...</body></html>";

And it works -- thanks!

However, now I'm thinking I would give users a choice between HTML and text.
Any ideas about formating a text version?

Regards,
Scott Natwick

"i. Wiin" <ii****@yagoo.com> wrote in message
news:Oy**************@TK2MSFTNGP12.phx.gbl...
Set MailFormat to a "1", which is HTML format. Then you can insert regular
HTML for formatting in your Body.

"Scott Natwick" <no****@yahoo.com> wrote in message
news:gs********************@comcast.com...
I'm trying to send an email from a Form. Here's what I have so far:

MailMessage mail = new MailMessage();
mail.To = "me@mycompany.com";
mail.From = "yo*@yourcompany.com";
mail.Subject = "this is a test email.";
mail.Body = "Line 1";
mail.Body += "Line 2";
mail.Body += "Line 3";

mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenti
cate","1"); //basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername
", "my_username_here"); //set your username here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword
", "super_secret"); //set your password here SmtpMail.SmtpServer =
"mail.mycompany.com"; //your real server goes here SmtpMail.Send(
mail );The example is from here:http://systemwebmail.com/faq/3.8.aspxThe
email sends and arrives successfully, however, I need to format
themessage.
I would like Line 1, Line 2, and Line 3 to be separate paragraphs.Any
ideas
how to do this?I have searched and found this:Carriage return character
(U+000D)Line feed character (U+000A)Carriage return character (U+000D)
followed by line feed character (U+000A)Line separator character (U+2028)
Paragraph separator character (U+2029)But I don't know if this is what I'm
looking for or how to use it.Thanks in advance,Scott Natwick


Nov 18 '05 #3
"Scott Natwick" <no****@yahoo.com> wrote in message
news:R7********************@comcast.com...
Any ideas about formating a text version?


"Formatting" and "text version" are pretty much exclusive i.e. you can't
have formatting in a text version because, by definition, it's text only.
You can have carriage returns, though, by using "\r\n"
Nov 18 '05 #4
Use Environment.NewLine.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Scott Natwick" <no****@yahoo.com> wrote in message
news:gs********************@comcast.com...
I'm trying to send an email from a Form. Here's what I have so far:

MailMessage mail = new MailMessage();
mail.To = "me@mycompany.com";
mail.From = "yo*@yourcompany.com";
mail.Subject = "this is a test email.";
mail.Body = "Line 1";
mail.Body += "Line 2";
mail.Body += "Line 3";
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenti
cate","1"); //basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername
", "my_username_here"); //set your username here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword
", "super_secret"); //set your password here SmtpMail.SmtpServer =
"mail.mycompany.com"; //your real server goes here SmtpMail.Send(
mail );The example is from here:http://systemwebmail.com/faq/3.8.aspxThe
email sends and arrives successfully, however, I need to format themessage.
I would like Line 1, Line 2, and Line 3 to be separate paragraphs.Any ideas
how to do this?I have searched and found this:Carriage return character
(U+000D)Line feed character (U+000A)Carriage return character (U+000D)
followed by line feed character (U+000A)Line separator character (U+2028)
Paragraph separator character (U+2029)But I don't know if this is what I'm
looking for or how to use it.Thanks in advance,Scott Natwick

Nov 18 '05 #5
Thanks, Mark

I was trying to use "\n" and it was blowing up. Once I switched to "\r\n",
like you suggested, it worked.

Scott

"Mark Rae" <ma**@mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:Ol**************@TK2MSFTNGP09.phx.gbl...
"Scott Natwick" <no****@yahoo.com> wrote in message
news:R7********************@comcast.com...
Any ideas about formating a text version?


"Formatting" and "text version" are pretty much exclusive i.e. you can't
have formatting in a text version because, by definition, it's text only.
You can have carriage returns, though, by using "\r\n"

Nov 18 '05 #6
Thanks Kevin,

I tested the Environment.NewLine like you suggeted, it works! Just what I
needed to know.

Scott

"Kevin Spencer" <ks******@takempis.com> wrote in message
news:ug**************@TK2MSFTNGP10.phx.gbl...
Use Environment.NewLine.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Scott Natwick" <no****@yahoo.com> wrote in message
news:gs********************@comcast.com...
I'm trying to send an email from a Form. Here's what I have so far:

MailMessage mail = new MailMessage();
mail.To = "me@mycompany.com";
mail.From = "yo*@yourcompany.com";
mail.Subject = "this is a test email.";
mail.Body = "Line 1";
mail.Body += "Line 2";
mail.Body += "Line 3";

mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenti
cate","1"); //basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername
", "my_username_here"); //set your username here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword
", "super_secret"); //set your password here SmtpMail.SmtpServer =
"mail.mycompany.com"; //your real server goes here SmtpMail.Send(
mail );The example is from here:http://systemwebmail.com/faq/3.8.aspxThe
email sends and arrives successfully, however, I need to format
themessage.
I would like Line 1, Line 2, and Line 3 to be separate paragraphs.Any
ideas
how to do this?I have searched and found this:Carriage return character
(U+000D)Line feed character (U+000A)Carriage return character (U+000D)
followed by line feed character (U+000A)Line separator character (U+2028)
Paragraph separator character (U+2029)But I don't know if this is what I'm
looking for or how to use it.Thanks in advance,Scott Natwick


Nov 18 '05 #7

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

Similar topics

2
by: The Pistoleer | last post by:
I'm looking for information (links) on formating a page intended for printing. Something more refined than the browser print menu, which tends to pring extra information in the header and footer....
1
by: Brian | last post by:
I have a project that I built that takes data from a recordset and then send an email to appropriate person. This process is using Access 2K and Outlook 2K. The email is going out as a RTF email...
3
by: Tom | last post by:
Is there any way to use conditional formating to change a control for a field in a continuous form to a textbox, option group or combobox depending on the value of another field on the form? On a...
2
by: Dan | last post by:
Hi all, I have a quick question about the formatting of external text files. I am trying to make a webpage for a local church that will display what is on in the coming weeks. I have done this...
2
by: just_me | last post by:
Hello, I'd like to ask if anyone knows the format /category/13/ where probably 13 is the ID if it's actually a directory/file and a script automatically created it when someone updated his site...
4
by: kent | last post by:
Hi, If a block box appears in an inline formating context, it will start a new line box. However, I can't find where this is stated in the CSS spec. Any pointer? Thanks!
0
by: Fonix | last post by:
I'm trying to make table border with pyExcelerator. As i can see there is only cell formating!? If i'm wrong pls tell me what is method to make more then one cell to have same format, other then...
2
by: sitko | last post by:
Hi, I'm in the process of converting a VB.net program into a C program so it can run on a unix like machine. I've been moving along at a nice pace, but this conversion has stumped me. I need...
4
by: =?Utf-8?B?QnJhc3NpY2FOaWdyYQ==?= | last post by:
Greetings, I am writing an application that prepares a quotation for a customer. The calculations are done in a SQL Server stored procedure. I use a datareader to fetch the record, but cannot...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.