pro_vb thread: Outlook From Field.
Hey Fergal,
Yeah, that stuff does not seem to work as advertised--it's such a drag...
I don't actually know if it's possible to open up two different exchange
mailboxes on the same machine simultaneously (at least with O2K). If you
look at the help file for the .LogOn method of the NameSpace object, you see
the alice-in-wonderland-esque description of it's NewSession parameter:
NewSession Optional Boolean. True to create a new session (doesn't use an
existing session). Multiple sessions cannot be created in Outlook.
One thing I did in order to make sure my app wasn't logging into *my*
exchange mailbox is to:
Open Outlook
Tools -> Options -> Mail Services
Select the "Prompt for a profile to be used" option under Startup
settings.
I think you can also use the ShowDialog argument of NameSpace.LogOn to make
the profile explicit.
HTH,
-Roy
Roy Pardee
Programmer/Analyst
SWFPAC Lockheed Martin IT
Extension 8487
-----Original Message-----
From: Fergal Kelly [mailto:fergal@s...]
Sent: Thursday, November 08, 2001 9:08 PM
To: professional vb
Subject: [pro_vb] RE: Outlook From Field.
Another one for you while I am at it (And I came across this trying to get a
work-around for the below). What I want to do sounds very easy but it won't
work (as usual). I want to read email using one account and reply using
another. So I created two Exchange Profiles on my machine (one of which
must be a default one), When I try a to logoff the default profile and log
into another It still opens up the default mailbox. In fact, even if try
.logon "totally imaginary profile name"
it opens the exchange default inbox.... Surely there is a way of logging on
and off different profiles and using outlook under each? Even if you don't
know what I am doing wrong I would appreciate any suggestions for a
workaround Thanks again...
Fergal
(Now I really can't wait to finish this Outlook project)
Exchange 2000
Outlook 2000
Windows 2000
Here's the code I pasted into a dummy app to test:
Dim o As Outlook.Application
Dim ns As Outlook.NameSpace
Dim f As Outlook.Folders
Dim strExtractedEmail As String
Dim msgs As Outlook.Items
Dim msg As MailItem
Private Sub Command1_Click()
Set ns = Application.GetNamespace("MAPI")
Set o = CreateObject("Outlook.Application")
Set ns = o.GetNamespace("MAPI")
Set msgs = ns.GetDefaultFolder(olFolderInbox).Items
Dim msg As MailItem
'Open a mail from the inbox and read out the subject
Set msg = msgs.GetLast
MsgBox msg.Subject
'Now quit outlook and the session
o.Quit
ns.Logoff
Set ns = Nothing
Set o = Nothing
End Sub
Private Sub Command2_Click()
Set ns = Application.GetNamespace("MAPI")
ns.Logon "ANYTHING YOU WANT AT ALL IN HERE FOR YOU WILL STILL GET THE
DEFAULT PROFILE OPENING"
Set o = CreateObject("Outlook.Application")
Set ns = o.GetNamespace("MAPI")
Set oItem = o.CreateItem(olMailItem)
'
With oItem
.To = "fergalkelly@h..."
.Body = "Body here"
.Subject = "This is the subject"
.Send
End With
ns.Logoff
End Sub
-----Original Message-----
From: Fergal Kelly [mailto:fergal@s...]
Sent: Friday, 9 November 2001 14:55
To: professional vb
Subject: [pro_vb] Outlook From Field.
Has anyone got sample code which can set the From Field in outbound mail (ie
Change the sender)? More: I am logged on via my VB app under my default
outlook profile but I need to send using another mailbox. You can achieve
this in outlook by using the From Field (You have to have permission to send
"from" that account)
Thanks much
(Can't wait to finish working with Outlook!)
-Fergal