Solved

newline email body C#

Posted on 2007-03-28
5
4,022 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C#.NET and microsoft certification. 3 40
Media.Imaging 1 18
Not seen Link button 5 37
tableview is not updating 1 6
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

813 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now