Is it possible to record the open emails in Outlook 2010 with PowerShell so that they can be opened again later? - powershell

This question is very similar to https://stackoverflow.com/questions/6839516/outlook-2010-reopen-messages which was closed as not being a question.
I have a bad habit of keeping emails open in Outlook 2010 as a reminder of what needs to be done during the day since I am constantly interrupted. What I would like to do is use PowerShell to get a list of the open emails so that if I need to close Outlook I know what I was working on before.
I am not worried about Outlook crashing, Outlook normally reopens all of the emails I had been working on automatically; the use case I am dealing with is when I have to manually close Outlook for a patch or to address some other issue.
What I would like to do is query the running Outlook process and see what messages are open; opening a new Outlook process via COM won't work since it would have a different list of open messages.
Does anyone know of a way to do this in PowerShell? I can use another language if needed, but have been attempting to standardize on PowerShell where possible so that other people here can reuse any code I write.
One possibility I have considered is to launch Outlook via PowerShell so that I have a way to interact with the running process.

First of all, you need to get a reference to the running Outlook instance.
$outlook = [System.Runtime.InteropServices.Marshal]::GetActiveObject('Outlook.Application')
Using the application object you then
Iterate through the outlook.Inspectors collection
Ask each individual Inspector for its CurrentItem
Store whatever properties you need from this item (date? subject? entry id?)

Related

Save Email as MSG file without using Outlook (COM object, etc.) or 3rd party software

Right now, I'm using the Exchange Web Services API with PowerShell to pull down specific emails from exchange and save them as EML files. This works great; however, the user/customer requires the emails to be in msg format. There are two ways that I've seen to do this:
Use Outlook/Outlook COM Object
Use a 3rd party library or software (like this: http://www.independentsoft.de/exchangewebservices/tutorial/downloadmessagetomsgfile.html)
Are there any other alternatives? I would like to stick with PowerShell if possible, but it seems like EWS might be limited to writing EML files.
There is no flexibility on the MSG vs EML requirement (compliance).
EDIT:
This will be run on a server; so I would prefer if this could be done without having Outlook installed.
You can still use PowerShell with the Outlook Object Model (OOM), if that's what you are hoping for.
You can also use Redemption, which has more features than OOM (it can also be run in a service, doesn't fire Outlook security prompts, etc.).
You can create an MSG file explicitly in your code (it is an OLE storage (IStorage) file and its format is documented) - parse the EML file, then populate various MAPI properties in the MSG file.
You can also use Redemption (I am its author). Converting an EML file to MSG is as easy as
RDOSession Session = new RDOSession();
RDOMail Msg = Session.CreateMessageFromMsgFile(#"c:\temp\YourMsgFile.msg");
Msg.Import(#"c:\temp\YourEmlFile.eml", rdoSaveAsType.olRFC822);
Msg.Save();

powershell - link to attached file in mail message

I can't find the solution for my problem. So, in my send-mailmessage html body is field that should be redirected to file which is included as attachment in message. How can I create hyperlink to that file in mail, when client opens it?
I don't know if you get my idea. In other words, in message I have attached file, and then there is field which should be a hyperlink to attached file. When client receives message he/she should press the link and then attached file opens.
I searched almost everything in everwhere but can't find a appropriate solution how to solve this.
This isn't really a PowerShell question, since this issue has nothing to do with the functionality of the Send-MailMessage cmdlet.
In any case, the reason you can't find a solution anywhere is that what you're trying to do is impossible. There is no way that a hyperlink in an e-mail message can point to a file attached to that message. Different mail clients on different operating systems store attachments in different locations. Even if you want to assume that all your recipients are running Outlook on Windows, there are different versions of both. Even if you know for a fact that all recipients are running a specific version of Outlook on a specific version of Windows, you're still out of luck. Outlook stores attachments in a subfolder in the Temporary Internet Files in the user's profile that has a randomly generated name. There's no way to inject code into a hyperlink in an email message, so without knowing the exact local file location, you can't link to it.
I suppose if you're really determined you could have the hyperlink point to a web page that runs some complex javascript code that tries to figure out where the attachment is stored, but that's a major undertaking, and would break if the recipient's default browser has javascript disabled.
Which begs the question, why exactly are you trying to do this? So that recipients can click once instead of having to double-click to open the attachment?
I have found that you can make a hyperlink point to a file share that you know the recipients have access to.
To do so:
Simply make each hyperlink point to the specific file and there you have it.
They have to have permissions to access that file share, or there is a much better way now that I haven't thought of.
Oh well, this works for me, for now.

Is there a way to get a reference to results after creating word documents using mail merge?

I'm using a VSTO 2010 AddIn to do a Word mail merge with WdMailMergeDestination being set to wdSendToNewDocument. Is there any way to get a reference to the newly created documents or even find out which data row was used to create each one?
Hi Christopher i am working on the same thing and so far i have managed to create an add-in for the outlook. So the Word mail merge completes and the mail in the Outlook outbox folder, right before being sent will attach the attachment of any type.
I am using this for mass scale i am talking about 5000-7000 mails at one go, and the add-in failed me, by attaching to only some emails its like on and off (my guess is the add-in not able to handle the heavy duty). So now i am going a bit further in to the solution by capturing the mailmerge object in the word. (btw i am using i am developing for 2007 should be no problem for 2010 as well)
So far i can suggest you this article that i managed to dig if you have a found a solution please do share tks.
http://support.microsoft.com/default.aspx?scid=kb;en-us;301659
P.S: I know that there are people selling this kind of software commercially.But its best if homebrewed!

Attaching files to an already open mail through VB.Net

I have a problem. I already have an outlook new mail message open. I need to programmatically attach files to the e-mail which is already open using vb.net. This is for a windows application. How could i do it? any ideas? please help!
The article here sounds specific to Outlook 2007 and VBA/Visual Basic, but is equally applicable to any Windows Application that wants to automate Outlook:
Automating Outlook from a Visual Basic Application [Outlook 2007 Developer Reference]:
http://msdn.microsoft.com/en-us/library/bb206737(office.12).aspx
Keep in mind the Caution disclaimer at the bottom over this "non-trusted" approach.
Once you're "in", you get get a handle to the active item via Application.ActiveInspector.CurrentItem. Then use MailItem.Attachments.Add.
You also need to keep this in mind:
Application Shutdown Changes in Outlook 2007 SP2:
http://msdn.microsoft.com/en-us/library/dd239276(office.12).aspx#ol2007AppLifecycle_ImpactforSolutions

Send To/Mail Recipient from WSH

I am trying to implement in windows scripting host the same function as windows Send To/Mail Recipient does. Did not find anything usefull on google except steps to instantiate Outlook.Application and directly calling its methods.
I need to go the same path as windows do, as there is a mix of Outlook and Lotus Notes installed, I don't see it good to perform some sort of testing and deciding which object to talk to...
What I have found is that the actual work is done by sendmail.dll, there is a handler defined in registry under HKEY_CLASSES_ROOT\CLSID\{9E56BE60-C50F-11CF-9A2C-00A0C90A90CE}. I would like either to use this dll somehow or to simulate the same steps it does.
Thanks for your input.
I found one item on CodeProject from 2003 that might be relevant.
The contents of the sent to menu in Windows is a bunch of files (usually links) in the C:\Documents and Settings\username\SendTo folder. You need to add your script - or a link to it - there.
For your script you could check if certain registry keys exist to detect Outlook and Lotus Notes.
Or if you don't care if the message shows up in sent items, just use CDOSYS.NewMail to send the message directly to the SMTP-server.
CDOSYS documentation