MSDN >
フォーラム ホーム
>
Visual Studio Tools for Office
>
How can I change credentials to read a particular mailbox?
How can I change credentials to read a particular mailbox?
I have a simple code to get all emails from exchange server using outlook lib.
Doesn’t mater what parameters I set for name , pass , it reads only my email mailbox
(where name is a Profile Name)
How can I change credentials to read a particular mailbox?
Outlook.Application outlook = new Outlook.ApplicationClass ();
Outlook.NameSpace ns = outlook.GetNamespace("Mapi" );
ns.Logon(name , pass , true , true );
Outlook.MAPIFolder inbox = ns.GetDefaultFolder(Outlook.OlDefaultFolders .olFolderInbox);
すべての返信
- Until now you only can have one Excahnge Inbox per Profile.
If you you want to connect to another Mailbox you need to create a temporary profile.
Another way is to open a shared folder if you have the access rights to the other inbox.
Something like this:
CalendarFolder =
ns.GetSharedDefaultFolder(myRecipient,Outlook.OlDefaultFolders .olFolderInbox);
http://msdn.microsoft.com/en-us/library/aa220116(office.11).aspx
Hope this helps,
greets - Helmut
Helmut Obertanner [http://www.x4u.de] [http://www.outlooksharp.de]- 回答としてマークTim LiMSFT, モデレータ2009年7月3日 5:47
- 回答としてマークされていないLucky7777 2009年7月3日 16:47
- Ok, thanks.
I have 2 Accounts (so two profiles)
trying "ns.Logon(A_ProfileName , pass , true , true ); " but it uses only default profile. (doesn't matter what profile name I use to Logon. - Is Outlook already running in the background when you are running this code?
Greets - Helmut
Helmut Obertanner [http://www.x4u.de] [http://www.outlooksharp.de] - I tried both cases (on/off outlook)
- Have you checked if there is an Outlook process running in the background using Task-Manager?
Sometimes other programms starting Outlook without a GUI.
e.g. Sidebar Widgets or Active Sync / Mobile Device Center.
Also make sure that you are using the correct Profilename.
Try to log it.
Must be working with two profiles.
Greets - Helmut
Helmut Obertanner [http://www.x4u.de] [http://www.outlooksharp.de] - I have no outlook scheduled tasks.
Checked "Windows Task Manager" - no outlook running.
Double checked Profile names.
ns.Logon() picks only default profile. - Hello Lucky,
I can remember - I programmed something using two different Outlook Profiles.
And that worked.
It was this article here:
http://www.codeproject.com/KB/office/BridgingTheGap.aspx
So - can you create a simple WinForms application with a combobox that has your 2 profile-names.
Your code should look like this.
// Create an Outlook session
object missing = System.Reflection.Missing.Value;
// get the Outlook Application Object
Outlook.Application outlookApplication = new Outlook.Application();
// get the namespace object
Outlook.NameSpace olNamespace = outlookApplication.GetNamespace("MAPI");
// Logon to Session, here we use the name from
// the comboBox to logon to a specific session.
// If there is already an Outlook instance with
// a Session - then this profile is used.
olNamespace.Logon(comboBox1.Text , missing, true, true);
try
{
// Only in Ol2007
MessageBox.Show(olNameSpace.CurrentProfileName);
}
catch (System.Exception ex)
{
MessageBox.Show(this,ex.Message);
}
finally
{
fabric = null;
olNamespace.Logoff();
olNamespace = null;
outlookApplication = null;
GC.Collect();
GC.WaitForPendingFinalizers();
}
Greets - Helmut
Helmut Obertanner [http://www.x4u.de] [http://www.outlooksharp.de]- 回答としてマークTim LiMSFT, モデレータ2009年7月3日 5:47
- 回答としてマークされていないLucky7777 2009年7月3日 16:50
Hello Lucky,
Right, but outlook doesn't pick another profile. All the time it runs only default one.
I can remember - I programmed something using two different Outlook Profiles.
And that worked.
It was this article here:
// Logon to Session, here we use the name from
// the comboBox to logon to a specific session.
// If there is already an Outlook instance with
// a Session - then this profile is used.
olNamespace.Logon(comboBox1.Text , missing, true , true );
Greets - Helmut
Helmut Obertanner [http://www.x4u.de] [http://www.outlooksharp.de]

