Read Email Body text

I want to create a application which can read the data in email body and store that data in sql server database. Email may contain data of many fields. Can you please suggest how would be the template of the email and how i can extract the data from email body.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Hello ziorinfo

Are you able to get the email to read from? Assuming you can, try formatting the email like this:


My E-Mail body content


Everything between those lines could be your content. You can use code like this to read it in.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;
using System.Xml.Linq;
using System.IO;

namespace dump
	class Program
		public string MyProperty { get; set; }

		static void Main(string[] args)
			FileStream fp = File.Open("File.txt", FileMode.Open, FileAccess.Read);

			StreamReader reader = new StreamReader(fp);

			// this is used to indicate if we are reading the email body or not
			bool state = false;

			// the email blocks
			List<string> blocks = new List<string>();
			string currentBlock = String.Empty;

				string line = String.Empty;
				while (true)
					line = reader.ReadLine();
					if (line == null)

					if (line == String.Empty)

					// are we entering or leaving an email body block?
					if (line == "###")
						// we are leaving a block, so save it
						if (state)

							currentBlock = String.Empty;

						state = !state;


					if (state)
						currentBlock = String.Format("{0}{1}\n\r",
			catch (Exception ex)


			foreach (var block in blocks)

			// don't exist just yet...

Open in new window

In which format you are getting the Mail?

If its in .NET Mail object format then you can directly read it.

Please refer the link below: 

Systme.Net.MailMessage  message = new MailMessage(); // Create a new Mail Message here.

// You can assign all the fields here.
// i.e.

message .ToAddress.Add("[To_Address]");
message.Body = "[Message_Bosy]";

You can format your mail message like this only.

If you are getting Mail Message in XML then I would say that first Parse your XML and form the MailMessage[] collection.

Once you get the collection, you can get the Body and can store them in SQL.

Éric MoreauSenior .Net ConsultantCommented:
I use this component to read emails:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Email Protocols

From novice to tech pro — start learning today.