|
-
Jun 22nd, 2006, 08:36 AM
#1
Thread Starter
New Member
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.
-
Jun 22nd, 2006, 07:57 PM
#2
Thread Starter
New Member
Re: Having problems opening email message from Visual Basic 5
-
Jun 22nd, 2006, 08:14 PM
#3
PowerPoster
Re: Having problems opening email message from Visual Basic 5
Last edited by rory; Jun 22nd, 2006 at 08:22 PM.
-
Jun 22nd, 2006, 08:22 PM
#4
Thread Starter
New Member
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
-
Jun 22nd, 2006, 08:32 PM
#5
PowerPoster
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")
-
Jun 22nd, 2006, 08:38 PM
#6
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.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 22nd, 2006, 08:44 PM
#7
PowerPoster
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
-
Jun 22nd, 2006, 08:59 PM
#8
Thread Starter
New Member
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
-
Jun 22nd, 2006, 09:03 PM
#9
Thread Starter
New Member
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?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|