Solved

Launch OutLook

Posted on 2004-04-22
15
704 Views
Last Modified: 2012-05-04
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?





0
Comment
Question by:melodiesoflife
  • 6
  • 5
  • 4
15 Comments
 
LVL 35

Accepted Solution

by:
[ fanpages ] earned 250 total points
ID: 10886362
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
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 10886425
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
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 10886441
Should it be "%0B" instead of "%0B%08"?  fanpages ;-)
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 10886622
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
 
LVL 6

Author Comment

by:melodiesoflife
ID: 10886727
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
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 10886784
Hi,

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

BFN,

fp.
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 10886808
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 49

Expert Comment

by:Ryan Chong
ID: 10889797
>>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
 
LVL 6

Author Comment

by:melodiesoflife
ID: 10890427
Hi ryancys

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

Do you have any suggest
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 10890508
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
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 10890610
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
 
LVL 6

Author Comment

by:melodiesoflife
ID: 10895731
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
 
LVL 6

Author Comment

by:melodiesoflife
ID: 10895978
Hi fanpages

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

That mean 13 and 10 in hexa
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 10896544
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
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 10896693
>>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

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now