Results 1 to 9 of 9

Thread: Having problems opening email message from Visual Basic 5

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Posts
    13

    Unhappy 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:
    1. Public Function OpenEmail(ByVal EmailAddress As String, _
    2.     Optional Subject As String, Optional Body As String) _
    3.     As Boolean
    4.  
    5.     Dim lWindow As Long
    6.     Dim lRet As Long
    7.     Dim sParams As String
    8.      
    9.     sParams = EmailAddress
    10.     If LCase(Left(sParams, 7)) <> "mailto:" Then _
    11.         sParams = "mailto:" & sParams
    12.  
    13.  If Subject <> "" Then sParams = sParams & "?subject=" & Subject
    14.          
    15.     If Body <> "" Then
    16.         sParams = sParams & IIf(Subject = "", "?", "&")
    17.         sParams = sParams & "body=" & Body
    18.     End If
    19.  
    20.    lRet = ShellExecute(lWindow, "open", sParams, _
    21.     vbNullString, vbNullString, SW_SHOW)
    22.      
    23.    OpenEmail = lRet = 0
    24.  
    25. 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.

  2. #2

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Posts
    13

    Re: Having problems opening email message from Visual Basic 5

    No one can help?

  3. #3
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: Having problems opening email message from Visual Basic 5

    edit .. checking now ..
    Last edited by rory; Jun 22nd, 2006 at 08:22 PM.

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Posts
    13

    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:
    1. Dim StrContents As String
    2.  
    3. Private Declare Function ShellExecute Lib "shell32.dll" Alias _
    4. "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation _
    5. As String, ByVal lpFile As String, ByVal lpParameters _
    6. As String, ByVal lpDirectory As String, _
    7. ByVal nShowCmd As Long) As Long
    8.  
    9. Private Const SW_SHOW = 5
    10.  
    11.  
    12. Public Function OpenEmail(ByVal EmailAddress As String, _
    13.     Optional Subject As String, Optional Body As String) _
    14.     As Boolean
    15.  
    16.     Dim lWindow As Long
    17.     Dim lRet As Long
    18.     Dim sParams As String
    19.    
    20.     sParams = EmailAddress
    21.     If LCase(Left(sParams, 7)) <> "mailto:" Then _
    22.         sParams = "mailto:" & sParams
    23.  
    24.  If Subject <> "" Then sParams = sParams & "?subject=" & Subject
    25.        
    26.     If Body <> "" Then
    27.         sParams = sParams & IIf(Subject = "", "?", "&")
    28.         sParams = sParams & "body=" & Body
    29.     End If
    30.  
    31.    lRet = ShellExecute(lWindow, "open", sParams, _
    32.     vbNullString, vbNullString, SW_SHOW)
    33.    
    34.    OpenEmail = lRet = 0
    35.  
    36. End Function
    37.  
    38.  
    39. Private Sub Book_Click()
    40.  
    41. Contact = "Contact: " & Contact.Text
    42. Phone = "Phone: " & Phone.Text
    43. Company = "Company: " & Company.Text
    44.  
    45.     StrContents = Contact & Phone & Company
    46.  
    47.     OpenEmail "[email protected]", "Bookings: ", StrContents
    48.  
    49. End Sub

    the line,

    VB Code:
    1. OpenEmail "[email protected]", "Bookings: ", StrContents

    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,

    VB Code:
    1. OpenEmail "[email protected]", "Bookings: ", StrContents & vbcrlf & StrContents2

    Also

    VB Code:
    1. 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:
    1. Contact = "Contact: " & Contact.Text & VbCrLF
    2. Phone = "Phone: " & Phone.Text & VbCrLF
    3. Company = "Company: " & Company.Text & VbCrLF

  5. #5
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    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")

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  7. #7
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    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

  8. #8

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Posts
    13

    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

  9. #9

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Posts
    13

    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
  •  



Click Here to Expand Forum to Full Width