473,769 Members | 6,107 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.c om";
mail.From = "yo*@yourcompan y.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.microso ft.com/cdo/configuration/smtpauthenticat e","1"); //basic authentication mail.Fields.Add ("http://schemas.microso ft.com/cdo/configuration/sendusername", "my_username_he re"); //set your username here mail.Fields.Add ("http://schemas.microso ft.com/cdo/configuration/sendpassword", "super_secret") ; //set your password here SmtpMail.SmtpSe rver = "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)Carriag e 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 8353
Set MailFormat to a "1", which is HTML format. Then you can insert regular
HTML for formatting in your Body.

"Scott Natwick" <no****@yahoo.c om> wrote in message
news:gs******** ************@co mcast.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.c om";
mail.From = "yo*@yourcompan y.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.microso ft.com/cdo/configuration/smtpauthenti
cate","1"); //basic authentication
mail.Fields.Add ("http://schemas.microso ft.com/cdo/configuration/sendusername
", "my_username_he re"); //set your username here
mail.Fields.Add ("http://schemas.microso ft.com/cdo/configuration/sendpassword
", "super_secret") ; //set your password here SmtpMail.SmtpSe rver =
"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)Carriag e 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>Te sting 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.c om> wrote in message
news:Oy******** ******@TK2MSFTN GP12.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.c om> wrote in message
news:gs******** ************@co mcast.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.c om";
mail.From = "yo*@yourcompan y.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.microso ft.com/cdo/configuration/smtpauthenti
cate","1"); //basic authentication
mail.Fields.Add ("http://schemas.microso ft.com/cdo/configuration/sendusername
", "my_username_he re"); //set your username here
mail.Fields.Add ("http://schemas.microso ft.com/cdo/configuration/sendpassword
", "super_secret") ; //set your password here SmtpMail.SmtpSe rver =
"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)Carriag e 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.c om> wrote in message
news:R7******** ************@co mcast.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.New Line.

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

"Scott Natwick" <no****@yahoo.c om> wrote in message
news:gs******** ************@co mcast.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.c om";
mail.From = "yo*@yourcompan y.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.microso ft.com/cdo/configuration/smtpauthenti
cate","1"); //basic authentication
mail.Fields.Add ("http://schemas.microso ft.com/cdo/configuration/sendusername
", "my_username_he re"); //set your username here
mail.Fields.Add ("http://schemas.microso ft.com/cdo/configuration/sendpassword
", "super_secret") ; //set your password here SmtpMail.SmtpSe rver =
"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)Carriag e 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******** ******@TK2MSFTN GP09.phx.gbl...
"Scott Natwick" <no****@yahoo.c om> wrote in message
news:R7******** ************@co mcast.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.New Line like you suggeted, it works! Just what I
needed to know.

Scott

"Kevin Spencer" <ks******@takem pis.com> wrote in message
news:ug******** ******@TK2MSFTN GP10.phx.gbl...
Use Environment.New Line.

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

"Scott Natwick" <no****@yahoo.c om> wrote in message
news:gs******** ************@co mcast.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.c om";
mail.From = "yo*@yourcompan y.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.microso ft.com/cdo/configuration/smtpauthenti
cate","1"); //basic authentication
mail.Fields.Add ("http://schemas.microso ft.com/cdo/configuration/sendusername
", "my_username_he re"); //set your username here
mail.Fields.Add ("http://schemas.microso ft.com/cdo/configuration/sendpassword
", "super_secret") ; //set your password here SmtpMail.SmtpSe rver =
"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)Carriag e 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
1712
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. Pete http://www.Pistoleer.com Retail & Wholesale (PH/FX 618-288-4588) _________________________________________________________________ A-Zoom snap-caps, Bore-Stores cases, Kleen-Bore gun care products Official Targets, Pachmayr grips/pads,...
1
2680
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 and I want to format some of the Fonts sizes and attributes like Bold or Italic. I can format the dates and numbers, but can't seem to get the Font Size and Color to change in code. Can someone please give me some tips on how to get this done. ...
3
1792
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 continuous form, I need some records to have a textbox, some to have an option group and some to have a combobox in the same field. Thanks, Tom
2
1318
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 using an external text file so that the future users will never have to modifiy the page itself. If left as plain text, it shows on the page in default format. I know I can format the text within the text file using standard HTML, but is
2
2782
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 or they just use a regex method to extract the number (which means /13/ is virtual), in our case '13' and then try "select 'bla bla' from table where id='13' " which is the same as "$id = $_GET;" with the second type of
4
1943
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
1751
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 just give them one-by-one. For little tables 100/20 formating cell by cell work ( i try with borders) fine. But when i get 5000/20 excel say: Too many different cell format! and excel remove some of the formats :( Pls help i need to format...
2
1749
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 a function to take two arguments:(a double number which may or may not be an integer, and an integer which will be the number of digits to store after the decimal place) it needs to turn this into a string which is always 10 characters long. if the...
4
1358
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 seem to get the data to format correctly. Since it is a quote I want the data in the format 12.34. Everything seems fine, except when I have a a zero at the end of the price, then I get 12.3. It needs to be 12.30. When I set the textbox value...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10045
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9863
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8870
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3958
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
2
3561
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.