• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1054
  • Last Modified:

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
0
cP6uH
Asked:
cP6uH
  • 6
  • 3
  • 2
  • +1
1 Solution
 
ptakjaCommented:
Try Environment.Newline in place of the vbCrLf.
0
 
cP6uHAuthor Commented:
I tried that too.. didn't work.

Dragan
0
 
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
Technology Partners: 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!

 
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
 
cP6uHAuthor 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
 
cP6uHAuthor 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
 
cP6uHAuthor 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
 
Fernando SotoCommented:
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
 
cP6uHAuthor 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 SotoCommented:
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
 
cP6uHAuthor Commented:
I did use % symbol, and instead of showing 10% GST, it gives me 10?ST.

Dragan
0
 
Fernando SotoCommented:
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

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 6
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now