Solved

newline email body C#

Posted on 2007-03-28
5
4,071 Views
Last Modified: 2008-01-09
I am trying to send an email using the default email client ( in C# 2005 )  in the following manner:

private void SendEmail ()
{
    string emailMessage;                // Email message to be sent
    string body;                              // Email message body
    string subject;                          // Email subject
           
    subject = Subject + "-" + ck.GetSiteCode2 ();
    body         = "Name:  "+ Environment.NewLine;
    body        += "Phone number:  " + Environment.NewLine;
    emailMessage = string.Format ( @"mailto:{0}?subject={1}&body={2}", MailTo, subject, body );
    Process.Start ( emailMessage );
}

It opens the Outlook email client with all the correct information except that body is not formatted properly.  It is showing like this:

Name:  Phone number:

and should be like this:

Name:
Phone Number:

What am I doing wrong?
0
Comment
Question by:jumanac14
  • 3
  • 2
5 Comments
 
LVL 15

Expert Comment

by:stanscott2
ID: 18812407
Try this:

Convert.ToChar(13).ToString() + Convert.ToChar(10).ToString();
0
 

Author Comment

by:jumanac14
ID: 18812591
Same result as before... any other suggestions?
0
 
LVL 15

Accepted Solution

by:
stanscott2 earned 500 total points
ID: 18812621
Try using "%0A" instead of the carriage return/line feeds.
0
 

Author Comment

by:jumanac14
ID: 18812687
It worked! Great expert advice...! would you mind explaining why it works like that?
0
 
LVL 15

Expert Comment

by:stanscott2
ID: 18812746
You're sending a URL, and the process will strip out any special characters.  To send these characters, you need to use hexadecimal:  line feed is 10 in ASCII, which is %0A in hex.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question