Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to open up an Outlook 'new mail' page?

Status
Not open for further replies.

Agent009

Programmer
Apr 4, 2003
96
0
0
IE
Hey,

I am programming a VB application, and when i select a button,i want to open up a new outlook email page and attach any selections i have made in the application to it.

How do i do this?,and what components+references do i have to select to make this possible?

Thank you in advance!
 
009,

Ah, Grasshopper, you have come to the right place ...

First things first. You will need to reference the Outlook object model appropriate to the version of office/Outlook you are using. In the References list, it will be called "Microsoft Outlook x.x Object Model". On my system, "x.x" is "9.0".

Now, to reference the object model and create a new mail item:
Code:
' These object names are the ones I've chosen, and I don't
' think they're by any means the best.  Choose ones that
' suit your programming style - and thy're bound to be
' better than these!

    Dim objOutlook As New Outlook.Application
    Dim objNameSpace As Outlook.NameSpace
    Dim objOutBox As MAPIFolder
    Dim objMail As MailItem

' Get the MAPI reference
    Set objNameSpace = objOutlook.GetNamespace("MAPI")

' Pick up the Outbox
    Set objOutBox = objNameSpace.GetDefaultFolder(olFolderOutbox)

' Add the mail item to the Outbox ...
    Set objMail = objOutBox.Items.Add
    With objMail

' I usually don't display the new message window, but
' instead do the whole setup in code.  Hence, I'm not 
' certain that this will actually display the window.
' You'll have to "fiddle" a bit.
        .Display

' Stuff I usually do, but if you're displaying the window,
' you'll probably be letting your user do this ...
        .Subject = txtSubject.Text
        .Body = txtMessage.Text

' Now, let's add an attachment ...
                .Attachments.Add attachment_name, olByValue, , attachment_description

    End With
[code]

The [i]attachment_name[/i] is the actual file you're going to attach, and [i]attachment_description[/i] is the text that will appear under the attachment.

Note that you can specify the sender and the recipients of the e-mail, but I think that is outside the brief of what you're trying to do, so I've left that code out.  You can either play around with the object model and the help the find out how to do it, or post back and I'll give you some sample code for that as well.

Happy mailing,

SmallCraig[upsidedown]
 
SmallCraig,

Thanks for replying to my query. It works like a dream.

Agent009
 
A quick search of FAQs would give you the alternative of doing it with or without using Outlook

Try faq222-179

Check also faq222-2244 to get the best answers
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top