I would like to access the contacts field on an email message (Email options) in outlook. Normally this field ties an email to a contact. Since it is a freeform text field available from the options dialog box, I am trying to use it to store a "next action" for my email message. I would like to set the next action based on the subject but I can't figure out how to access thas field from the outlook.mailitem object
Thanks
Jim
I think this will answer it: the field is buried in a semi-generic 'Links' property, with a type of olContact. To test the following code, open a new email, put something in the contacts field, and then run the code:
Sub ShowContactsField()
Dim objApp As Outlook.Application
Dim ActiveMailItem As Inspector
Dim currLink As Link
Set objApp = CreateObject("Outlook.Application")
If TypeName(objApp.ActiveWindow) = "Inspector" Then
If objApp.ActiveInspector.CurrentItem.Class = olMail Then
For Each currLink In objApp.ActiveInspector.CurrentItem.Links
If currLink.Type = olContact Then
MsgBox currLink.Name
End If
Next
End If
End If
Set objApp = Nothing
End Sub
In general, I agree with Oliver; this probably isn't the best place to store what you're looking for, but at least it's exposed in the native form. Check the field length, I think it might be limited to 255.
Hmm, I also couldn't figure out how to access the Contacts field but from your description it sounds like you're not intending to use it for its intended purpose at all but rather just have the need to associate some arbitrary string data with an email item. If that is correct, I would recommend adding fields to the UserProperties collection instead.
There are easier way to get Contacts list - by using Links property of oMailItem object:
For i = 1 To mailItem.Links.Count
If mailItem.Links.item(i).Type = olContact Then
Debug.Print mailItem.Links.item(i).Name
End If
Next i
Related
I am developing an outlook add in that retrieves a TaskItem from outlook desktop and opens it. Here is my code.
private static Microsoft.Office.Interop.Outlook.TaskItem GetLatestTask(string entryId)
{
Microsoft.Office.Interop.Outlook.MAPIFolder taskFolder = Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks);
List<Microsoft.Office.Interop.Outlook.TaskItem> liTask = new List<Microsoft.Office.Interop.Outlook.TaskItem>();
foreach (Microsoft.Office.Interop.Outlook.TaskItem taskItem in taskFolder.Items)
{
if (taskItem.EntryID == entryId)
return taskItem;
}
}
This works fine usually. However if i update the task from outlook web/Office online, then try to get the task using the code, the task i get is not updated and still contains the old values.
So for example i have a task with a subject named "Test" then i update this in outlook web to "Test Updated", I would still get a task with a subject named "Test".
If I check the task list in outlook desktop, I can see that the task's subject has already been updated in the Task list. However opening it would still display the old item.
Once I restart Outlook, The add in gets the updated item.
Can anyone point me in the right direction? Thank you.
First of all, iterating over all items in the folder is not really a good idea:
foreach (Microsoft.Office.Interop.Outlook.TaskItem taskItem in taskFolder.Items)
{
if (taskItem.EntryID == entryId)
return taskItem;
}
Instead, you may consider using the Find/FindNext or Restrict methods of the Items class. Read more about them in the following articles with code sample:
How To: Use Find and FindNext methods to retrieve Outlook mail items from a folder (C#, VB.NET)
How To: Use Restrict method to retrieve Outlook mail items from a folder
Also relying on the EntryID property for identifying items in Outlook is not the best way. The Entry ID changes when an item is moved into another store, for example, from your Inbox to a Microsoft Exchange Server public folder, or from one Personal Folders (.pst) file to another .pst file. Solutions should not depend on the EntryID property to be unique unless items will not be moved. Instead, you may introduce your own custom property for identifying items.
If you use cached data most probably you need to sync your data with the server side. SyncObjects is a set of SyncObject objects representing the Send/Receive groups for a user. Use the SyncObjects property to return the SyncObjects object from a NameSpace object.
Set mySyncObjects = Application.GetNameSpace("MAPI").SyncObjects
The SyncObject.Start method begins synchronizing a user's folders using the specified Send\Receive group.
Public Sub Sync()
Dim nsp As Outlook.NameSpace
Dim sycs As Outlook.SyncObjects
Dim syc As Outlook.SyncObject
Dim i As Integer
Dim strPrompt As Integer
Set nsp = Application.GetNamespace("MAPI")
Set sycs = nsp.SyncObjects
For i = 1 To sycs.Count
Set syc = sycs.Item(i)
strPrompt = MsgBox( _
"Do you wish to synchronize " & syc.Name &"?", vbYesNo)
If strPrompt = vbYes Then
syc.Start
End If
Next
End Sub
Hopefully, after that, your items will be updated with a new data.
We have user with 3-4 shared email address in Outlook.
I am developing add-in where it will extract the email address of selected store and will get it's contact folder from People.
My problem is I don't know how to get email address of SelectedStore.
Here is my code.
string recipientName = SelectedStore.EmailAddress; // This is what I want to make it work
Outlook.Recipient recip = ns.CreateRecipient(recipientName);
recip.Resolve();
if (recip.Resolved)
{
Outlook.MAPIFolder folderContacts = ns.GetSharedDefaultFolder(recip, Outlook.OlDefaultFolders.olFolderContacts);
}
Any help will be appreciated.
Thank you.
For the mailbox owner, you can either try to read the MAPIFolder.Store property to get to the parent store, then read the PR_MAILBOX_OWNER_ENTRYID property (DASL name "http://schemas.microsoft.com/mapi/proptag/0x661B0102") using Store.PropertyAccessor.GetProperty. You can then use the store owner entry id to call Namespace.GetAddressEntryFromID. Once you have the AddressEntry object, you can use AddressEntry.GetExchangeUser.PrimarySmtpAddress.
Note that PR_MAILBOX_OWNER_ENTRYID property is only available in the online stores. You might want to use Redemption (I am its author) and its RDOExchangeMailboxStore.Owner.SmtpAddress property. RDOExchangeMailboxStore can be retrieved using RDOSession.GetRDOObjectfromOutlookObject(Store) or using RDOSession.GetStoreFromID.
You can also try to retrieve the store entry id and parse it - its format is documented and you can extract the EX type address of the owner. You can then construct the GAL entry id to open the AddressEntry object. From there, you can retrieve the SMTP address.
Just to let you know, I found the solution.
Outlook.MAPIFolder folderContacts = store.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
should do the trick.
I have created custom user property in Outlook called "Ownership". When someone from the team claim ownership of an email, person's name is saved as its value.
My question, is there any way to enumerate all the values of this custom property into combo box.
In simple words, get a list of all team members names (whoever has claimed ownership of an email in inbox folder).
I want to do something like this.
Outlook.UserDefinedProperties userDefinedProperties = null;
Outlook.UserDefinedProperty userDefinedProperty = null;
Outlook.MAPIFolder currentFolder = application.ActiveExplorer().CurrentFolder;
mailUserProperties = currentFolder.UserDefinedProperties;
mailUserProperty = mailUserProperties["Ownership"];
// Filling up the combo box
PersonCombo.Items.Add(userDefinedProperty.Value);
I want to use current folder because folder will have all the values while an email can only have one value of the custom property.
If this is not possible, is there any other way to get it done?
Thank you in advance.
There isn't a single query that will return all unique values of a particular named property. The best you can do is search for all items where the property exists (not null), and then build a list of unique values.
I do not think, however, this is a good of storing possible values - it really must be a single source, such as a particular GAL distribution list, or a hidden (associated) message in the folder that stores all possible values in a single property.
Thanks everyone for your input.
At the end, I ended up creating GAL distribution list as Dmitry suggested and used it for my purpose.
I am looking for a solution to send automated emails from my website to PHPList lists. From my understanding, PHPList's emails are authored manually using the web-based interface provided by the application. Are there some APIs I can use to allow my website to send emails directly?
You can just code one like this, just need to change some of the values on the insert strings to match your list. So when someone creates and account on your website, you just call a routine like this and insert it into PHPLIST.
You can also do it with a trigger on your members table. The code below is VB.NET - but you can easily convert it to php.
Public Sub AddMemberToPHPList(ByVal vUserEmail As String)
Dim moConn As MySqlConnection
moConn = New MySqlConnection("server=*********;User Id=******;Password=*******;Persist Security Info=True;database=phplist;Ssl Mode=None;Allow User Variables=True;")
moConn.Open()
Dim oMySqlCommand As New MySqlCommand
oMySqlCommand.Connection = moConn
oMySqlCommand.Parameters.AddWithValue("email_address", vUserEmail.ToLower)
oMySqlCommand.Parameters.AddWithValue("uniqid", Guid.NewGuid)
oMySqlCommand.CommandText = "INSERT IGNORE INTO phplist_user_user set email = ?email_address, confirmed=1,entered = now(),modified = now(),uniqid = ?uniqid,htmlemail = 1, bouncecount=0,disabled = 0"
oMySqlCommand.CommandType = CommandType.Text
oMySqlCommand.ExecuteNonQuery()
oMySqlCommand.CommandText = "INSERT IGNORE INTO phplist_listuser set userid = (select id from phplist_user_user where email = ?email_address) , listid = 3, entered = now(), modified= now()"
oMySqlCommand.ExecuteNonQuery()
End Sub
first, if is a list of emails, yo need use queues, you only need have the emails stored in a database, and then sending through queues with a cicle of the emails of the database
This reply is rather late I realize, but I think you'd do well to look into this plugin for PHPList:
https://resources.phplist.com/plugin/submitbymail
The plugin page says that the author is no longer supporting/developing the plugin, but the code that is there should work on current versions of PHPList.
I used to use an older plugin (called 'MailToList') for this exact purpose - someone can compose an email somewhere else, send it to a specific address on their system, and then the plugin watches those email inboxes for new emails and will queue up a new 'campaign' using that email as the source. So you essentially have to set up one email inbox for each list you want to send out to in PHPList.
(I'm just going through an upgrade process on my PHPList system and will probably use this 'SubmitByMail' plugin since the 'MailToList' plugin appears to not exist any more. But I haven't yet actually used the 'SubmitByMail' plugin.)
I wanted to count no. of objects on Google homepage using static programming, i mean without creating object first(the way we do in dynamic one).
Pls tell me what is wrong in below statement
Set P = Browser("creationtime:=0").page("title:=Google").WebButton("type:=submit","html tag:=INPUT")
MsgBox P.Count()
Pls help, screenshot of error is attached here.
Thanks
You can get the total number of buttons by using descriptive approach.
Set odesc = description.Create()
odesc("micclass").value="WebButton"
Set i = Browser("creationtime:=0").Page("title:=Google").ChildObjects(odesc)
Msgbox i.Count()
Set i = Nothing : Set odesc = Nothing
You are actually trying to get a count of the child webbutton objects on that page object. With the original code that you posted, if there is more than one webbutton object on the page with the descriptors you're using, QTP will throw a multiple object matches found error.
Nelly's code regarding the description property is what you're after. If you are specifically looking for the count of all webbutton objects with a type:=submit, you can add additional description properties:
odesc("micclass").value="WebButton"
odesc("type").value="submit"
doing this will filter out buttons that don't have the matching type value