Launch OutLook

Hi all

I in my program, I want to launch OutLook and put something in the body of mail.
I do like that:

'Declare
Private Const SW_SHOW = 1

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

'*******************
Sub Navigate(ByVal NavTo As String)
    Dim hBrowse As Long
    hBrowse = ShellExecute(0&, "open", NavTo, "", "", SW_SHOW)    
End Sub

Then I call Navigate like that:

Navigate "mailto:someone@somewhere.com?subject=" & _
                            "My subject&body=" & _
                            strText1 & vbCrLf & strText2

I insert vbCrlf because I want an empty line between strText1 and strText2. But it don't has any effect.
How can I insert an empty line between strText1 and strText2?





LVL 6
melodiesoflifeAsked:
Who is Participating?
 
[ fanpages ]Connect With a Mentor IT Services ConsultantCommented:
Hi melodiesoflife,

Try replacing vbCrLf with "escaped" characters for Carriage Return & Line Feed.

e.g.

Navigate "mailto:someone@somewhere.com?subject=" & _
                            "My subject&body=" & _
                            strText1 & "%0B%08" & strText2

The prefix of "%" indicates the values are in Octal.

BFN,

fp.
0
 
Ryan ChongCommented:
You can try create a User Form, where the user can type in the info like : Receiver, Receiver Name, Subject, Body Message, Attahment, etc into the form. Then try add the M$ Outlook Object Library in order to send out the email:

Example on the "Send Now" button:

Private Sub cmdSendNow_Click()
    Dim iOutlook As Outlook.Application
    Dim myApp As Outlook.MailItem
    Set iOutlook = New Outlook.Application
    Set myApp = iOutlook.CreateItem(olMailItem)
    temp = "Username"
    txtMessage = "Hello World Again!"
    AttachFile = "C:\Documents and Settings\Administrator\My Documents\My Pictures\next.gif"
    myApp.To = "user@domain.com"
    myApp.Subject = "Hello World!"
    myApp.Attachments.Add AttachFile
    myApp.Body = "Hi " & temp & vbCrLf & vbCrLf & txtMessage
    'myApp.HTMLBody = ""
    myApp.Send
    Do While iOutlook.GetNamespace("MAPI").GetDefaultFolder(olFolderOutbox).Items.Count <> 0
        DoEvents
    Loop
    MsgBox "Successfully Sent", vbInformation, "Email Sent"
End Sub

Customize the example above to suit your requirement, i think this will be the most effective way to present your application.

Hope this helps
0
 
Ryan ChongCommented:
Should it be "%0B" instead of "%0B%08"?  fanpages ;-)
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
[ fanpages ]IT Services ConsultantCommented:
First one is "%0B" (that's capital "b" as this is the octal code for decimal 13 - a carriage return), the second one is "%08" - the octal code for line feed (decimal 10).

Together you get <CR><LF>.

If you just want a <CR> use "%0B" or just a <LF> use "%08".

BFN,

fp.
0
 
melodiesoflifeAuthor Commented:
Hi fanpages

I have try but it don't effect.
When strText1 = "a" and strText2 = "b" I hope the result in outlook is:

a
b

but it show a strange character: a b

'***************************************

Hi ryancys

When use Outlook.Application and so on, I must register library before used but I can't find it, where it is?
0
 
[ fanpages ]IT Services ConsultantCommented:
Hi,

Is your MS-Outlook e-mail set to HTML format as default?

BFN,

fp.
0
 
[ fanpages ]IT Services ConsultantCommented:
Sorry... may just be a "quirk" of MS-Outlook.

I tried two %0B characters & this seemed to be OK!

mailto:someone@somewhere.com?subject=My subject&body=body%0B%0Bbody2

Results in:

===
body

body2
===

In the message text.

BFN,

fp.
0
 
Ryan ChongCommented:
>>When use Outlook.Application and so on, I must register library before used but I can't find it, where it is?
In the case you need to use Outlook Objects in your application, you Must include the Library from the References, you Should able to find the M$ Outlook Object Library from References (goto menu Project > References) IF you installed the M$ Outlook in your machine.
0
 
melodiesoflifeAuthor Commented:
Hi ryancys

I installed the MS Outlook, but I don't see Outlook Object Library in Referrences dialog.

Do you have any suggest
0
 
[ fanpages ]IT Services ConsultantCommented:
Hi again,

Did:

mailto:someone@somewhere.com?subject=My subject&body=body%0B%0Bbody2

Not work?

Or are you just trying alternate method(s)?

BFN,

fp.
0
 
Ryan ChongCommented:
Try find the "Microsoft Outlook 9.0 Object Library" from References (10.0 for XP, etc)

if still Not found, simply click the Browse, the go to:

<Office or Outlook install folder>\Office\MSOUTL9.OLB (9.0, for 10.0 look for something like MSOUTL10.OLB)

Example:

C:\Program Files\Office2000\Office\MSOUTL9.OLB

select the file then click the Open button. And Now the Library should added to the list.

regards
0
 
melodiesoflifeAuthor Commented:
Hi  ryancys.

well, I see. But what happen if my customer's computer don't install  MS Office (I see that MSOUTL9.OLB is installed when I install MS Outlook).
I only want to use Outlook Express, which included in Window, I don't want to install anythings else.

'********************

Hi fanpages.

mailto:someone@somewhere.com?subject=My subject&body=body%0B%0Bbody2

I don't know why but it still not work.
0
 
melodiesoflifeAuthor Commented:
Hi fanpages

I found it. not %0B%08. It must %0D%0A.

That mean 13 and 10 in hexa
0
 
[ fanpages ]IT Services ConsultantCommented:
Hi,

Glad you found a solution in the end.

Yes, I would ordinarily use ASCII code 13 (decimal) for <CR> & 10 (decimal) for <LF>.

In fact there are too in-built VB/VBA constants vbCR & vbLF (and also vbCRLF) that are set to these values; you may like to use those.


The %0B%0B [double zero 'B'] works via HTML!?!

Yet another Micro$o£t oddity.

Thanks for the points/grading.

Happy codin',

BFN,

fp.
[http://NigelLee.info]
0
 
Ryan ChongCommented:
>>But what happen if my customer's computer don't install  MS Office
Ya, that's the sad place, if you can use the Outlook Library, sure your presentation will be better.

or you can try use this free component to send mail instead:
vbSendMail.dll Version 3.65-- Easy E-mail Sending in VB, with Attachments
http://www.freevbcode.com/ShowCode.Asp?ID=109

cheers
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.