Inspector outdated

D

DanielH

Hi,

I am using the following code in my ItemSend-notification to get the name of
the account from which the current eMail will be sent [C#-Plugin]:
void applicationObject_ItemSend(object oItem, ref bool Cancel)
{
Outlook.MailItem Item = oItem as Outlook.MailItem;
string senderAddress = "";
Outlook.Inspector OLI = Item.GetInspector;
CommandBars CBs;
CommandBarPopup CBP;
object ID_ACCOUNTS = 31224;
if(OLI==null)
return;
CBs = OLI.CommandBars;
object type = 10;
object visible = 1;
CBP = CBs.FindControl(type, ID_ACCOUNTS, null, visible) as
CommandBarPopup;
if(CBP == null)
return;
object index = 1;
CommandBarControl MC = CBP.Controls[index];
int pos = MC.Caption.IndexOf(' ');
if(pos >= 0)
senderAddress = MC.Caption.Substring(0, pos);
else
senderAddress = MC.Caption;


Actually, this kind of works, but I am always one iteration behind. Imagine,
I change from default to account2, then click Send, I will receive Default.
Changing it again to account2, I will get account2.
Anyone knows this problem? Any workaround?

Kind regards,
Daniel
 
D

Dmitry Streblechenko

You need to be checking the named MAPI properties set on the message when
you select an account rather than check the state of the dropdown control on
the inspector.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
D

DanielH

Can you please give me an example.
If I could get the final eMail-Adress which will be used this would be even
better.

Dmitry Streblechenko said:
You need to be checking the named MAPI properties set on the message when
you select an account rather than check the state of the dropdown control on
the inspector.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

DanielH said:
Hi,

I am using the following code in my ItemSend-notification to get the name
of
the account from which the current eMail will be sent [C#-Plugin]:
void applicationObject_ItemSend(object oItem, ref bool Cancel)
{
Outlook.MailItem Item = oItem as Outlook.MailItem;
string senderAddress = "";
Outlook.Inspector OLI = Item.GetInspector;
CommandBars CBs;
CommandBarPopup CBP;
object ID_ACCOUNTS = 31224;
if(OLI==null)
return;
CBs = OLI.CommandBars;
object type = 10;
object visible = 1;
CBP = CBs.FindControl(type, ID_ACCOUNTS, null, visible) as
CommandBarPopup;
if(CBP == null)
return;
object index = 1;
CommandBarControl MC = CBP.Controls[index];
int pos = MC.Caption.IndexOf(' ');
if(pos >= 0)
senderAddress = MC.Caption.Substring(0, pos);
else
senderAddress = MC.Caption;


Actually, this kind of works, but I am always one iteration behind.
Imagine,
I change from default to account2, then click Send, I will receive
Default.
Changing it again to account2, I will get account2.
Anyone knows this problem? Any workaround?

Kind regards,
Daniel
 
D

Dmitry Streblechenko

Not in the Outlook Object Model... You can use Extended MAPI (C++ or Delphi
only) to read the following named prop

{00062008-0000-0000-C000-000000000046}, 0x8581, PT_STRING8

to get the account id, then use the recently documented IOlkAccountManager
interface to retrieve the corresponding account. Once you have IOlkAccount
object, you can call IOlkAccount::GetProp(0x000C001F) to read the e-mail
address.
If the property is not set on the message, that means the default accout is
being used, so you can call IMAPISession::QueryIdentity to retrieve the
current user's name and address.

<plug>

You can also use Redemption (url below) to read the account used to send the
message:

'save it first to make sure MAPI can see the latest changes
MailItem.Save

'reopen the given message (MailItem) as Redemption.RDOMail
set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT
set Msg = Session.GetMessageFromID(MailItem.EntryID)

'get the account info
set Account = Msg.Account
if (Account is Nothing) Then
'default account
MsgBox Session.CurrentUser.SMTPAddress
Else
if Account.AccountType = 0 Then 'atPOP3
MsgBox Account.SMTPAddress
end if
End If

</plug>

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

DanielH said:
Can you please give me an example.
If I could get the final eMail-Adress which will be used this would be
even
better.

Dmitry Streblechenko said:
You need to be checking the named MAPI properties set on the message when
you select an account rather than check the state of the dropdown control
on
the inspector.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

DanielH said:
Hi,

I am using the following code in my ItemSend-notification to get the
name
of
the account from which the current eMail will be sent [C#-Plugin]:
void applicationObject_ItemSend(object oItem, ref bool Cancel)
{
Outlook.MailItem Item = oItem as Outlook.MailItem;
string senderAddress = "";
Outlook.Inspector OLI = Item.GetInspector;
CommandBars CBs;
CommandBarPopup CBP;
object ID_ACCOUNTS = 31224;
if(OLI==null)
return;
CBs = OLI.CommandBars;
object type = 10;
object visible = 1;
CBP = CBs.FindControl(type, ID_ACCOUNTS, null, visible) as
CommandBarPopup;
if(CBP == null)
return;
object index = 1;
CommandBarControl MC = CBP.Controls[index];
int pos = MC.Caption.IndexOf(' ');
if(pos >= 0)
senderAddress = MC.Caption.Substring(0, pos);
else
senderAddress = MC.Caption;


Actually, this kind of works, but I am always one iteration behind.
Imagine,
I change from default to account2, then click Send, I will receive
Default.
Changing it again to account2, I will get account2.
Anyone knows this problem? Any workaround?

Kind regards,
Daniel
 
D

DanielH

Thanks a lot!

Dmitry Streblechenko said:
Not in the Outlook Object Model... You can use Extended MAPI (C++ or Delphi
only) to read the following named prop

{00062008-0000-0000-C000-000000000046}, 0x8581, PT_STRING8

to get the account id, then use the recently documented IOlkAccountManager
interface to retrieve the corresponding account. Once you have IOlkAccount
object, you can call IOlkAccount::GetProp(0x000C001F) to read the e-mail
address.
If the property is not set on the message, that means the default accout is
being used, so you can call IMAPISession::QueryIdentity to retrieve the
current user's name and address.

<plug>

You can also use Redemption (url below) to read the account used to send the
message:

'save it first to make sure MAPI can see the latest changes
MailItem.Save

'reopen the given message (MailItem) as Redemption.RDOMail
set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT
set Msg = Session.GetMessageFromID(MailItem.EntryID)

'get the account info
set Account = Msg.Account
if (Account is Nothing) Then
'default account
MsgBox Session.CurrentUser.SMTPAddress
Else
if Account.AccountType = 0 Then 'atPOP3
MsgBox Account.SMTPAddress
end if
End If

</plug>

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

DanielH said:
Can you please give me an example.
If I could get the final eMail-Adress which will be used this would be
even
better.

Dmitry Streblechenko said:
You need to be checking the named MAPI properties set on the message when
you select an account rather than check the state of the dropdown control
on
the inspector.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

Hi,

I am using the following code in my ItemSend-notification to get the
name
of
the account from which the current eMail will be sent [C#-Plugin]:
void applicationObject_ItemSend(object oItem, ref bool Cancel)
{
Outlook.MailItem Item = oItem as Outlook.MailItem;
string senderAddress = "";
Outlook.Inspector OLI = Item.GetInspector;
CommandBars CBs;
CommandBarPopup CBP;
object ID_ACCOUNTS = 31224;
if(OLI==null)
return;
CBs = OLI.CommandBars;
object type = 10;
object visible = 1;
CBP = CBs.FindControl(type, ID_ACCOUNTS, null, visible) as
CommandBarPopup;
if(CBP == null)
return;
object index = 1;
CommandBarControl MC = CBP.Controls[index];
int pos = MC.Caption.IndexOf(' ');
if(pos >= 0)
senderAddress = MC.Caption.Substring(0, pos);
else
senderAddress = MC.Caption;


Actually, this kind of works, but I am always one iteration behind.
Imagine,
I change from default to account2, then click Send, I will receive
Default.
Changing it again to account2, I will get account2.
Anyone knows this problem? Any workaround?

Kind regards,
Daniel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top