Having problems opening email message from Visual Basic 5
Hi all :)
I'm using the below function, to open a new email message, and feed in an email address, subject and a 'body' of the email (Note I don't want to send an email, just open the message and paste in contents)...
VB Code:
Public Function OpenEmail(ByVal EmailAddress As String, _
Optional Subject As String, Optional Body As String) _
As Boolean
Dim lWindow As Long
Dim lRet As Long
Dim sParams As String
sParams = EmailAddress
If LCase(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
lRet = ShellExecute(lWindow, "open", sParams, _
vbNullString, vbNullString, SW_SHOW)
OpenEmail = lRet = 0
End Function
The problem is, I want to feed a 'body' of text that includes returns after each line of text. As it stands, it just feeds one long line of text, containing company name, phone number etc. I've tried VbCrlF, Sendkeys to send tabs to the email message etc, nothing seems to work.
It just pastes a huge long line of information. I've tried putting vbCrLF's at the end of the strings that are grouped together (with '&') to form the final body string etc, no go...
Any ideas? I'm using VB5 to do this.
Re: Having problems opening email message from Visual Basic 5
Re: Having problems opening email message from Visual Basic 5
Re: Having problems opening email message from Visual Basic 5
Here is the entire contents of the program
And my apologies, it's using VB6 not VB5
VB Code:
Dim StrContents As String
Private Declare Function ShellExecute Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation _
As String, ByVal lpFile As String, ByVal lpParameters _
As String, ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Private Const SW_SHOW = 5
Public Function OpenEmail(ByVal EmailAddress As String, _
Optional Subject As String, Optional Body As String) _
As Boolean
Dim lWindow As Long
Dim lRet As Long
Dim sParams As String
sParams = EmailAddress
If LCase(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
lRet = ShellExecute(lWindow, "open", sParams, _
vbNullString, vbNullString, SW_SHOW)
OpenEmail = lRet = 0
End Function
Private Sub Book_Click()
Contact = "Contact: " & Contact.Text
Phone = "Phone: " & Phone.Text
Company = "Company: " & Company.Text
StrContents = Contact & Phone & Company
End Sub
the line,
Uses the function to open a new email message in outlook, with the email address as [email protected], the subject as 'bookings' and the body as 'StrContents'. Problem is, StrContents is made up of company, address and phone number. I want these lines seperated by return (so they are individual lines) - however this function dumps them all in as one long line of text.
I've tried,
Also
VB Code:
OpenEmail "
[email protected]", "Bookings: ", StrContents & SendKeys (send some carriage returns) & StrContents2
Also tried adding the returns somewhere else, like in the original 3 strings...
VB Code:
Contact = "Contact: " & Contact.Text & VbCrLF
Phone = "Phone: " & Phone.Text & VbCrLF
Company = "Company: " & Company.Text & VbCrLF
Re: Having problems opening email message from Visual Basic 5
ok use vbNewLine or vbCrlf then this ..
or just use "%0D%0A" as the next line in the body string ..
sParams = Replace(sParams, Chr(13), "%0D%0A")
Re: Having problems opening email message from Visual Basic 5
There are several characters that you will need t oparse and make url safe. the carriage return is just one. There is a thread about it with working code on the forums already. I think Merri or Merrion was the member that posted it.
Re: Having problems opening email message from Visual Basic 5
yeah i just found that on google here ..
http://www.rondebruin.nl/mail/oebody.htm
Re: Having problems opening email message from Visual Basic 5
Sorry guys - I really appreciate the feedback, but could someone specify where
sParams = Replace(sParams, Chr(13), "%0D%0A")
Needs to go, and how it actually affects the function?.. I like to understand the code before using it, and I wouldn't know where to even 'insert' that line :)
Sorry for my noobishness :P
Re: Having problems opening email message from Visual Basic 5
Wait, I understand now, thanks :)
%0D%0A will just seperate each string in the body.
I'm confused though - is this simply because VBCRLF etc won't parse into an email message?