By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,333 Members | 1,047 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,333 IT Pros & Developers. It's quick & easy.

Newline in body text of e-mail message using mailto

P: n/a
I am using mailto to open the default e-mail program on the users machine
using the following function code snippet that I found on th web.:-

Public Function OpenEmail(ByVal EmailAddress As String, _
Optional ByVal Subject As String = "", Optional ByVal Body As String = "")
As Boolean
Dim bAns As Boolean = True
Dim sParams As String
sParams = EmailAddress
If LCase(Strings.Left(sParams, 7)) <> "mailto:" Then sParams = "mailto:" &
sParams
If Subject <> "" Then sParams = sParams & "?subject=" & Subject
If Body <> "" Then
sParams = sParams & IIf(Subject = "", "?", "&")
sParams = sParams & "body=" & Body
End If
Try
System.Diagnostics.Process.Start(sParams)
Catch
bAns = False
End Try
Return bAns
End Function

All that I want to be abl to do is to place newline characters into the Body
area of the text. I thought that this would be simple, but nothing that I
have tried seems to work! Can anyone help please??

Many thanks

Paul Bromley
Nov 20 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a

"Paul Bromley" <fl*******@dsl.pipex.com> wrote in message
news:eR*************@TK2MSFTNGP11.phx.gbl...
All that I want to be abl to do is to place newline characters into the Body area of the text. I thought that this would be simple, but nothing that I
have tried seems to work! Can anyone help please??


%0d%0a
Nov 20 '05 #2

P: n/a
Hi Paul,

Why not use this one.

\\\by Fergus Cooney & small correction Cor
'A reference to System.Web may be necessary
'in the Project for this Import to work.
Imports System.Web.HttpUtility
Public Sub StartDefaultMail (sTo As String, _
Optional sSubject As String = "", _
Optional sMessage As String = "")
Try
sTo = UrlEncode (sTo)
sSubject = sSubject
sMessage = sMessage
Process.Start ("mailto:" & sTo & "?subject=" _
& sSubject & "&body=" & sMessage)
Catch e As Exception
MsgBox ("Couldn't start default email application" _
& vbCrLf & e.Message)
'or
Throw New Exception ("Couldn't start default email app", e)
End Try
End Sub
///

(As Herfried tested is possible that sSubject = sSubject can be needed as
sSubject = UrlEncode(sSubject) the same with the sMessage that you have to
try yourself)

I hope this helps a little bit?

Cor
Nov 20 '05 #3

P: n/a
Excuse my ignorance Jeff, but does %0d%0a go in as part of a string??

Best wishes

Paul Bromley

"Jeff Johnson" <i.***@enough.spam> wrote in message
news:OV**************@TK2MSFTNGP09.phx.gbl...

"Paul Bromley" <fl*******@dsl.pipex.com> wrote in message
news:eR*************@TK2MSFTNGP11.phx.gbl...
All that I want to be abl to do is to place newline characters into the

Body
area of the text. I thought that this would be simple, but nothing that I have tried seems to work! Can anyone help please??


%0d%0a

Nov 20 '05 #4

P: n/a
Hi Cor,

sMessage = UrlEncode(sMessage) does work, but I now get + instead of a
space, which reading the documentation is correct. I also need to check what
else gets changed. I was hoping to use this to send details re ini files for
my application, and for sendin details of the PC spcifciation.

Best wishes
Paul Bromley


"Cor Ligthert" <no**********@planet.nl> wrote in message
news:eT**************@TK2MSFTNGP09.phx.gbl...
Hi Paul,

Why not use this one.

\\\by Fergus Cooney & small correction Cor
'A reference to System.Web may be necessary
'in the Project for this Import to work.
Imports System.Web.HttpUtility
Public Sub StartDefaultMail (sTo As String, _
Optional sSubject As String = "", _
Optional sMessage As String = "")
Try
sTo = UrlEncode (sTo)
sSubject = sSubject
sMessage = sMessage
Process.Start ("mailto:" & sTo & "?subject=" _
& sSubject & "&body=" & sMessage)
Catch e As Exception
MsgBox ("Couldn't start default email application" _
& vbCrLf & e.Message)
'or
Throw New Exception ("Couldn't start default email app", e)
End Try
End Sub
///

(As Herfried tested is possible that sSubject = sSubject can be needed as
sSubject = UrlEncode(sSubject) the same with the sMessage that you have to
try yourself)

I hope this helps a little bit?

Cor

Nov 20 '05 #5

P: n/a

"Paul Bromley" <fl*******@dsl.pipex.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Excuse my ignorance Jeff, but does %0d%0a go in as part of a string??


Check out the examples:

http://msdn.microsoft.com/library/de...asp?frame=true
Nov 20 '05 #6

P: n/a
Thanks for that Jeff, should have tried it before asking. It is part of the
string. I have taken my sBodyText or whatever and done a replace on the text
replacing the relevant return characters with "%0d%0a" prior to calling
mailto. Many thanks for this.

Paul Bromley

"Jeff Johnson [MVP: VB]" <i.***@enough.spam> wrote in message
news:O$**************@TK2MSFTNGP09.phx.gbl...

"Paul Bromley" <fl*******@dsl.pipex.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl.
Excuse my ignorance Jeff, but does %0d%0a go in as part of a string??
Check out the examples:

http://msdn.microsoft.com/library/de...asp?frame=true

Nov 20 '05 #7

P: n/a
I had the same issue you did (turning all spaces in the body to + signs) so
I just do a string.replace to turn the +'s into %20, which works fine for my
application, because I know there will never be a + sign in a valid email.
Private Sub CreateEmailMessage(ByVal Address As String, ByVal Subject As
String, ByVal Body As String)

Dim psi As New ProcessStartInfo

Dim tempPath As String

psi.UseShellExecute = True

'kludge to fix UrlEncode turning all spaces into + signs.

tempPath = "mailto:" & HttpUtility.UrlEncode(Address) & "?subject=" &
HttpUtility.UrlEncode(Subject) & "&body=" & HttpUtility.UrlEncode(Body)

psi.FileName = tempPath.Replace("+", "%20")

Process.Start(psi)

End Sub

"Paul Bromley" <fl*******@dsl.pipex.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi Cor,

sMessage = UrlEncode(sMessage) does work, but I now get + instead of a
space, which reading the documentation is correct. I also need to check what else gets changed. I was hoping to use this to send details re ini files for my application, and for sendin details of the PC spcifciation.

Best wishes
Paul Bromley

Nov 20 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.