VSTO outlook mailItem Application_ItemSend to catach a contactItem from a recipient of Active Directory
how to get ContactItem from Recipients property by Active directory. I had trid the code and get the ContactItem seccsussful when the Recipients is saved in local contact. how to get the ContactItem when a Recipients was only exists only on Active directory.
public void Application_ItemSend(object mail, ref bool Cancel)
{
Outlook.MAPIFolder fldContacts = (Outlook.MAPIFolder)Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
for (int i = 1; i < mail.Recipients.Count + 1; i++)
{
Outlook.Recipient r = mail.Recipients.Item(i);
if (!r.Resolved) r.Resolve();
if (r.Resolved)
{
Outlook.ContactItem ci = (fldContacts.Items.Find("[Email1Address] = '" + r.Address + "'") as Outlook.ContactItem);
if (ci != null)
{
//to get the Department of Recipient
string DepartmentName = ci.Department;
}
}
}
}
outlook vsto contactitem
add a comment |
how to get ContactItem from Recipients property by Active directory. I had trid the code and get the ContactItem seccsussful when the Recipients is saved in local contact. how to get the ContactItem when a Recipients was only exists only on Active directory.
public void Application_ItemSend(object mail, ref bool Cancel)
{
Outlook.MAPIFolder fldContacts = (Outlook.MAPIFolder)Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
for (int i = 1; i < mail.Recipients.Count + 1; i++)
{
Outlook.Recipient r = mail.Recipients.Item(i);
if (!r.Resolved) r.Resolve();
if (r.Resolved)
{
Outlook.ContactItem ci = (fldContacts.Items.Find("[Email1Address] = '" + r.Address + "'") as Outlook.ContactItem);
if (ci != null)
{
//to get the Department of Recipient
string DepartmentName = ci.Department;
}
}
}
}
outlook vsto contactitem
the ci ContactItem is already null. I don`t know where is wrong.
– SuperDeve
Nov 26 '18 at 5:39
add a comment |
how to get ContactItem from Recipients property by Active directory. I had trid the code and get the ContactItem seccsussful when the Recipients is saved in local contact. how to get the ContactItem when a Recipients was only exists only on Active directory.
public void Application_ItemSend(object mail, ref bool Cancel)
{
Outlook.MAPIFolder fldContacts = (Outlook.MAPIFolder)Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
for (int i = 1; i < mail.Recipients.Count + 1; i++)
{
Outlook.Recipient r = mail.Recipients.Item(i);
if (!r.Resolved) r.Resolve();
if (r.Resolved)
{
Outlook.ContactItem ci = (fldContacts.Items.Find("[Email1Address] = '" + r.Address + "'") as Outlook.ContactItem);
if (ci != null)
{
//to get the Department of Recipient
string DepartmentName = ci.Department;
}
}
}
}
outlook vsto contactitem
how to get ContactItem from Recipients property by Active directory. I had trid the code and get the ContactItem seccsussful when the Recipients is saved in local contact. how to get the ContactItem when a Recipients was only exists only on Active directory.
public void Application_ItemSend(object mail, ref bool Cancel)
{
Outlook.MAPIFolder fldContacts = (Outlook.MAPIFolder)Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
for (int i = 1; i < mail.Recipients.Count + 1; i++)
{
Outlook.Recipient r = mail.Recipients.Item(i);
if (!r.Resolved) r.Resolve();
if (r.Resolved)
{
Outlook.ContactItem ci = (fldContacts.Items.Find("[Email1Address] = '" + r.Address + "'") as Outlook.ContactItem);
if (ci != null)
{
//to get the Department of Recipient
string DepartmentName = ci.Department;
}
}
}
}
outlook vsto contactitem
outlook vsto contactitem
asked Nov 26 '18 at 5:21
SuperDeveSuperDeve
113
113
the ci ContactItem is already null. I don`t know where is wrong.
– SuperDeve
Nov 26 '18 at 5:39
add a comment |
the ci ContactItem is already null. I don`t know where is wrong.
– SuperDeve
Nov 26 '18 at 5:39
the ci ContactItem is already null. I don`t know where is wrong.
– SuperDeve
Nov 26 '18 at 5:39
the ci ContactItem is already null. I don`t know where is wrong.
– SuperDeve
Nov 26 '18 at 5:39
add a comment |
2 Answers
2
active
oldest
votes
You could refer to the below code:
bool resolved;
Microsoft.Office.Interop.Outlook.Application olApplication = new Microsoft.Office.Interop.Outlook.Application();
// get nameSpace and logon.
Microsoft.Office.Interop.Outlook.NameSpace olNameSpace = olApplication.GetNamespace("mapi");
olNameSpace.Logon("Outlook", "", false, true);
// get the Calender items
Microsoft.Office.Interop.Outlook.MAPIFolder _olCalender = olNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
// Get the Items (Appointments) collection from the Calendar folder.
Microsoft.Office.Interop.Outlook.Items oItems = _olCalender.Items;
foreach (object o in oItems)
{
if (o is Microsoft.Office.Interop.Outlook.AppointmentItem)
{
Microsoft.Office.Interop.Outlook.Recipients recipients = ((Microsoft.Office.Interop.Outlook.AppointmentItem)o).Recipients;
foreach (Microsoft.Office.Interop.Outlook.Recipient rec in recipients)
{
resolved = rec.Resolve();
if (resolved)
{
Microsoft.Office.Interop.Outlook.ContactItem contactItem = rec.AddressEntry.GetContact();
}
}
}
}
For more information, Please refer to this link:
C# Outlook get CompanyName property from Recipient
Thank you for your comment . I had trid it when you add the comment,but it wasn`t used when the recipe exsits only on Active Directory.
– SuperDeve
Nov 26 '18 at 6:36
add a comment |
just change the code like the folowing:
Outlook.ContactItem ci =
(fldContacts.Items.Find("[Email1Address] = '" + r.Address + "'") as Outlook.ContactItem);
change to
ExchangeUser contactItem = recip.AddressEntry.GetExchangeUser();
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53475124%2fvsto-outlook-mailitem-application-itemsend-to-catach-a-contactitem-from-a-recipi%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You could refer to the below code:
bool resolved;
Microsoft.Office.Interop.Outlook.Application olApplication = new Microsoft.Office.Interop.Outlook.Application();
// get nameSpace and logon.
Microsoft.Office.Interop.Outlook.NameSpace olNameSpace = olApplication.GetNamespace("mapi");
olNameSpace.Logon("Outlook", "", false, true);
// get the Calender items
Microsoft.Office.Interop.Outlook.MAPIFolder _olCalender = olNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
// Get the Items (Appointments) collection from the Calendar folder.
Microsoft.Office.Interop.Outlook.Items oItems = _olCalender.Items;
foreach (object o in oItems)
{
if (o is Microsoft.Office.Interop.Outlook.AppointmentItem)
{
Microsoft.Office.Interop.Outlook.Recipients recipients = ((Microsoft.Office.Interop.Outlook.AppointmentItem)o).Recipients;
foreach (Microsoft.Office.Interop.Outlook.Recipient rec in recipients)
{
resolved = rec.Resolve();
if (resolved)
{
Microsoft.Office.Interop.Outlook.ContactItem contactItem = rec.AddressEntry.GetContact();
}
}
}
}
For more information, Please refer to this link:
C# Outlook get CompanyName property from Recipient
Thank you for your comment . I had trid it when you add the comment,but it wasn`t used when the recipe exsits only on Active Directory.
– SuperDeve
Nov 26 '18 at 6:36
add a comment |
You could refer to the below code:
bool resolved;
Microsoft.Office.Interop.Outlook.Application olApplication = new Microsoft.Office.Interop.Outlook.Application();
// get nameSpace and logon.
Microsoft.Office.Interop.Outlook.NameSpace olNameSpace = olApplication.GetNamespace("mapi");
olNameSpace.Logon("Outlook", "", false, true);
// get the Calender items
Microsoft.Office.Interop.Outlook.MAPIFolder _olCalender = olNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
// Get the Items (Appointments) collection from the Calendar folder.
Microsoft.Office.Interop.Outlook.Items oItems = _olCalender.Items;
foreach (object o in oItems)
{
if (o is Microsoft.Office.Interop.Outlook.AppointmentItem)
{
Microsoft.Office.Interop.Outlook.Recipients recipients = ((Microsoft.Office.Interop.Outlook.AppointmentItem)o).Recipients;
foreach (Microsoft.Office.Interop.Outlook.Recipient rec in recipients)
{
resolved = rec.Resolve();
if (resolved)
{
Microsoft.Office.Interop.Outlook.ContactItem contactItem = rec.AddressEntry.GetContact();
}
}
}
}
For more information, Please refer to this link:
C# Outlook get CompanyName property from Recipient
Thank you for your comment . I had trid it when you add the comment,but it wasn`t used when the recipe exsits only on Active Directory.
– SuperDeve
Nov 26 '18 at 6:36
add a comment |
You could refer to the below code:
bool resolved;
Microsoft.Office.Interop.Outlook.Application olApplication = new Microsoft.Office.Interop.Outlook.Application();
// get nameSpace and logon.
Microsoft.Office.Interop.Outlook.NameSpace olNameSpace = olApplication.GetNamespace("mapi");
olNameSpace.Logon("Outlook", "", false, true);
// get the Calender items
Microsoft.Office.Interop.Outlook.MAPIFolder _olCalender = olNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
// Get the Items (Appointments) collection from the Calendar folder.
Microsoft.Office.Interop.Outlook.Items oItems = _olCalender.Items;
foreach (object o in oItems)
{
if (o is Microsoft.Office.Interop.Outlook.AppointmentItem)
{
Microsoft.Office.Interop.Outlook.Recipients recipients = ((Microsoft.Office.Interop.Outlook.AppointmentItem)o).Recipients;
foreach (Microsoft.Office.Interop.Outlook.Recipient rec in recipients)
{
resolved = rec.Resolve();
if (resolved)
{
Microsoft.Office.Interop.Outlook.ContactItem contactItem = rec.AddressEntry.GetContact();
}
}
}
}
For more information, Please refer to this link:
C# Outlook get CompanyName property from Recipient
You could refer to the below code:
bool resolved;
Microsoft.Office.Interop.Outlook.Application olApplication = new Microsoft.Office.Interop.Outlook.Application();
// get nameSpace and logon.
Microsoft.Office.Interop.Outlook.NameSpace olNameSpace = olApplication.GetNamespace("mapi");
olNameSpace.Logon("Outlook", "", false, true);
// get the Calender items
Microsoft.Office.Interop.Outlook.MAPIFolder _olCalender = olNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
// Get the Items (Appointments) collection from the Calendar folder.
Microsoft.Office.Interop.Outlook.Items oItems = _olCalender.Items;
foreach (object o in oItems)
{
if (o is Microsoft.Office.Interop.Outlook.AppointmentItem)
{
Microsoft.Office.Interop.Outlook.Recipients recipients = ((Microsoft.Office.Interop.Outlook.AppointmentItem)o).Recipients;
foreach (Microsoft.Office.Interop.Outlook.Recipient rec in recipients)
{
resolved = rec.Resolve();
if (resolved)
{
Microsoft.Office.Interop.Outlook.ContactItem contactItem = rec.AddressEntry.GetContact();
}
}
}
}
For more information, Please refer to this link:
C# Outlook get CompanyName property from Recipient
answered Nov 26 '18 at 6:25
Alina LiAlina Li
633125
633125
Thank you for your comment . I had trid it when you add the comment,but it wasn`t used when the recipe exsits only on Active Directory.
– SuperDeve
Nov 26 '18 at 6:36
add a comment |
Thank you for your comment . I had trid it when you add the comment,but it wasn`t used when the recipe exsits only on Active Directory.
– SuperDeve
Nov 26 '18 at 6:36
Thank you for your comment . I had trid it when you add the comment,but it wasn`t used when the recipe exsits only on Active Directory.
– SuperDeve
Nov 26 '18 at 6:36
Thank you for your comment . I had trid it when you add the comment,but it wasn`t used when the recipe exsits only on Active Directory.
– SuperDeve
Nov 26 '18 at 6:36
add a comment |
just change the code like the folowing:
Outlook.ContactItem ci =
(fldContacts.Items.Find("[Email1Address] = '" + r.Address + "'") as Outlook.ContactItem);
change to
ExchangeUser contactItem = recip.AddressEntry.GetExchangeUser();
add a comment |
just change the code like the folowing:
Outlook.ContactItem ci =
(fldContacts.Items.Find("[Email1Address] = '" + r.Address + "'") as Outlook.ContactItem);
change to
ExchangeUser contactItem = recip.AddressEntry.GetExchangeUser();
add a comment |
just change the code like the folowing:
Outlook.ContactItem ci =
(fldContacts.Items.Find("[Email1Address] = '" + r.Address + "'") as Outlook.ContactItem);
change to
ExchangeUser contactItem = recip.AddressEntry.GetExchangeUser();
just change the code like the folowing:
Outlook.ContactItem ci =
(fldContacts.Items.Find("[Email1Address] = '" + r.Address + "'") as Outlook.ContactItem);
change to
ExchangeUser contactItem = recip.AddressEntry.GetExchangeUser();
answered Nov 26 '18 at 7:14
SuperDeveSuperDeve
113
113
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53475124%2fvsto-outlook-mailitem-application-itemsend-to-catach-a-contactitem-from-a-recipi%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
the ci ContactItem is already null. I don`t know where is wrong.
– SuperDeve
Nov 26 '18 at 5:39