Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

newline email body C#

Posted on 2007-03-28
5
Medium Priority
?
4,184 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 2000 total points
ID: 18812621
Try using "%0A" instead of the carriage return/line feeds.
1
 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

The purpose of this article is to demonstrate how we can use conditional statements using Python.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

670 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