vbCrLf, vbNewLine not working

Hi,

I'm trying to send an email from the application.
The code I'm using is

Process.Start("mailto:?subject=" & strSubject & "&body=" & strBody)

example of strBody = "Text1" & vbCrLf & "Text2" & vbCrLf & "Text3"

What I get in the email is Text1Text2Text3 where it should be
Text1
Text2
Text3

Can someone tell me how to get this working?

Thanks,
Dragan
cP6uHIT ManagerAsked:
Who is Participating?
 
Fernando SotoRetiredCommented:
Hi cP6uH;

The following statement is from the The mailto URL scheme documentation.

   RFC 1738 requires that many characters in URLs be encoded. This
   affects the mailto scheme for some common characters that might
   appear in addresses, headers or message contents. One such character
   is space (" ", ASCII hex 20).  Also note that line breaks in the
   body of a message MUST be encoded with "%0D%0A".

So replace all vbCrLf or Environment.Newline with "%0D%0A" as shown below.

        Dim nl As String = "%0D%0A"
        strBody = "Text1" & nl & "Text2" & nl & "Text3"


Fernando
0
 
ptakjaCommented:
Try Environment.Newline in place of the vbCrLf.
0
 
cP6uHIT ManagerAuthor Commented:
I tried that too.. didn't work.

Dragan
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
ptakjaCommented:
Got it. Try this:

       Dim strSubject As String = "Test message"
        Dim strBody As String = System.Web.HttpUtility.UrlEncode("Text1" & vbCrLf & "Text2" & vbCrLf & "Text3")
        Process.Start("mailto:?subject=" & strSubject & "&body=" & strBody)
0
 
bruintjeCommented:
Hello cP6uH,

in addition there are 2 parts to that solution by ptakja

1. background > http://dotnet.mvps.org/dotnet/faqs/?id=openfileappwebpage&lang=en
2. you need to add a reference to System.Web dll
3. add this line in above your VB class > imports System.Web

then you have the availability to the httputility class using UrlEncode method and yes it works as i tested it here :)

hope this helps a bit
bruintje
0
 
cP6uHIT ManagerAuthor Commented:
It works fine for smaller string, but a string that I create is pretty large. So when I tried it, i got the following error:
---------------------------
Application error
---------------------------
A serious error has occurred.

Source: System

Access is denied
---------------------------
OK  
---------------------------

Also, by using that it puts + instead of space. Fixed that by using Replace() function, but that might not be good if the string has a + in there somewhere.

Dragan
0
 
bruintjeCommented:
think you need to escape those characters as in html, are you sending html in the string? there is also a limitation on the length you can send this way not sure what it is but read something about more then 1000[1024?] characters
0
 
cP6uHIT ManagerAuthor Commented:
I'm not sending any html in the string.
If there is a limit, then I need a different way of doing this since my string will be way more then 1024 characters.

Dragan
0
 
cP6uHIT ManagerAuthor Commented:
Is there any other way to open a default email client and add text to subject and body?

The user will specify To: address when the form opens up.

Dragan
0
 
cP6uHIT ManagerAuthor Commented:
Fernando,

That works fine. Can you tell me how do I encode % to show?

I will give you points because your solution works the best. I still need to figure out how to send a really big string to a body of the email of the default email client, so I'll open a new question for that.

Thanks,
Dragan
0
 
Fernando SotoRetiredCommented:
Just use the % symble in the body. The % must be followed by two hex digits to have special meaning.

Let me research the other part of the question and I will get back to you.

Fernando
0
 
cP6uHIT ManagerAuthor Commented:
I did use % symbol, and instead of showing 10% GST, it gives me 10?ST.

Dragan
0
 
Fernando SotoRetiredCommented:
Hi cP6uH;

I used this code:

        Dim strSubject As String = "This is a test"
        Dim strBody As String
        strBody = "I did use % symbol, and instead of showing 10% GST, it gives me 10?ST."
        Process.Start("mailto:?subject=" & strSubject & "&body=" & strBody)

And got this in the e-mail body.

I did use % symbol, and instead of showing 10% GST, it gives me 10?ST.

I was not able to find anything on a procedure to get the default mail client to be used except for what we have been using above.

Fernando
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.