Newline in body text of e-mail message using mailto

P

Paul Bromley

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
 
J

Jeff Johnson

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
 
C

Cor Ligthert

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
 
P

Paul Bromley

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

Best wishes

Paul Bromley
 
P

Paul Bromley

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
 
P

Paul Bromley

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
 
K

Kevin Hodgson

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top