Results 1 to 15 of 15

Thread: using the shell to popup default email client

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2001
    Location
    London
    Posts
    31

    using the shell to popup default email client

    Hi,
    I have a button on my form that when clicked it pops-up the default email client with a few of it's field filled such as "Subject" and "body".

    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
    (ByVal hwnd As Long, ByVal lpszOp As String, _
    ByVal lpszFile As String, ByVal lpszParams As String, _
    ByVal LpszDir As String, ByVal FsShowCmd As Long) _
    As Long
    Private Const SW_SHOWNORMAL = 1




    Private Sub Send_Click()
    Dim l As Long
    l = ShellExecute(Me.hwnd, "Open", "mailto:?Subject=Hello&Body=Thought you would like to download this ." + Chr(13) + "PC users here - download the file to your desktop and start using. ", "", "C:\", SW_SHOWNORMAL)
    End Sub


    The problem is that I would like to format the text in the body of the message but do not know what character to insert in order to get sentences on new lines in the body section. I tried using Chr(13) also "\n" and "\r" but none of them worked.

    I am assuming that most of the users will have Outlook or Outlook Express as their email client and was wondering if anyone could help me find out how to do it.

    Thank you
    Why did I ever start learning VB?! I should have been happy with Java.

  2. #2
    Addicted Member Gavin_Mannion's Avatar
    Join Date
    Aug 2001
    Location
    London, UK
    Posts
    214
    Have you tried CRLF?

    Works for me in other instances..

    hth
    Gavin


  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    I believe he means vbCrLf

    I've done similiar things, and have discovered that if I use a Richtextbox for my users to create the message that my code will pop into the message area of an EMail, I have a lot more formatting options that just using a standard text box.

    Richtextboxes support a lot more features than a standard, such as carriage return/line feeds, bolding, etc.

  4. #4
    Addicted Member Gavin_Mannion's Avatar
    Join Date
    Aug 2001
    Location
    London, UK
    Posts
    214
    Originally posted by Hack
    I believe he means vbCrLf
    Well actually no, I use just plain CRLF and it works, is there any difference between the 2 or should I just put the VB infront for best practice reasons?
    Gavin Mannion

    Jackofalltrades.

    "Some people are alive simply because it is against the law to kill them." - Anonymous

    //TODO: Insert smart comment here

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Aug 2001
    Location
    London
    Posts
    31
    none of the suggested characters worked. It sounds like a sound ideea to use a a Richtextbox but the text is not going to be typed by the user. It is preset text. Please help as I have the deadline for Monday. Cheers
    Why did I ever start learning VB?! I should have been happy with Java.

  6. #6
    PowerPoster eiSecure's Avatar
    Join Date
    Jul 2000
    Location
    Texas
    Posts
    2,209
    Well, you could always load it into a regular textbox with multiline set to true. You could then hide the textbox from the user by setting it's visible property to false. Then, you could just load it in.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Aug 2001
    Location
    London
    Posts
    31
    I tried it but it does not work. How do I get Richtextbox into my project?
    Why did I ever start learning VB?! I should have been happy with Java.

  8. #8
    PowerPoster eiSecure's Avatar
    Join Date
    Jul 2000
    Location
    Texas
    Posts
    2,209
    Right-click on your toolbox. Select Components..., and check off MS RichEdit (something like that, forgot exact name).

    Then, click OK.

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Aug 2001
    Location
    London
    Posts
    31
    i set the Text of the control to "blablabla"+ vbCrLf +"blablabla" and when I popup the email client (Outlook Express) i use RichEdit1.Text as the body of the message and it all appears on only one line. Is it possible for you to show me what string you would set the Rich edit text to? Thanks
    Why did I ever start learning VB?! I should have been happy with Java.

  10. #10
    PowerPoster eiSecure's Avatar
    Join Date
    Jul 2000
    Location
    Texas
    Posts
    2,209
    ...I would use the & operator instead of the + operator.

  11. #11
    PowerPoster eiSecure's Avatar
    Join Date
    Jul 2000
    Location
    Texas
    Posts
    2,209
    Does changing the constant to vbNewLine work?

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Aug 2001
    Location
    London
    Posts
    31
    still no luck. I do not understand why
    Why did I ever start learning VB?! I should have been happy with Java.

  13. #13
    PowerPoster eiSecure's Avatar
    Join Date
    Jul 2000
    Location
    Texas
    Posts
    2,209
    Me neither...

  14. #14
    Lively Member nfo1212's Avatar
    Join Date
    Aug 2001
    Location
    Near Boston, U.S.A.
    Posts
    82

    Solution

    This thread is a bit old but I found the solution for your (and my) problem.
    Code:
    '****************************************************************************
    '
    '                   PUBLIC CONSTANT FOR A LINE BREAK IN SHELLEXECUTE-
    '                   GENERATED EMAIL USING HEX VALUES
    '****************************************************************************
    Public Const mailNewLine = "%0D%0A"
    just use the mailNewLine like you would vbCrLf ("blah" & mailNewLine & "blah")

  15. #15

    Thread Starter
    Junior Member
    Join Date
    Aug 2001
    Location
    London
    Posts
    31
    thanks, I just about managed to find it also.I think I was looking in the wrong place(VB documentation) when that character is a "mailto" protocol!?
    On the Netscape site I only found "%0A" as a new line. What is the other character "%0D"?
    Why did I ever start learning VB?! I should have been happy with Java.

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