Solved

newline email body C#

Posted on 2007-03-28
5
4,130 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

617 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