Solved

newline email body C#

Posted on 2007-03-28
5
3,994 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
Comment Utility
Try this:

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

Author Comment

by:jumanac14
Comment Utility
Same result as before... any other suggestions?
0
 
LVL 15

Accepted Solution

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

Author Comment

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

Expert Comment

by:stanscott2
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
c# code 19 57
Check my code out(2) 1 26
Long URL in SMS 6 23
Get String split 5 31
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
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.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.

744 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