I'm trying to read some data from a .pst file using powershell and I can't seem to extract some attributes for mail items, specifically:
recipients, sender, cc, bcc, body
for some reason when I try to access these properties from code it shows up as blank. Most of the other properties show up file (subject, attachments etc...)
I'm using the following code:
$objOutlook = new-object -ComObject Outlook.Application
$ns = $objOutlook.GetNamespace("MAPI")
$ns.AddStore($pst.FullName)
$folders = $ns.Folders
$archiveStore = $ns.Folders[$pst.Name.Replace(".pst","")]
from there I just use Folders and Items recursively to get my mail items.
Any ideas?
This returns the sender for me.
$archiveStore.Items | %{$_.SenderName}
Which property are you using to fetch the recipients,sender,cc,bcc,body?
Where and how do you run a PowerShell script? And what code exactly do you use to fetch the property values?
The fact is that Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment. See Considerations for server-side Automation of Office for more information.
Related
I'm looking into a script that can access an Outlook folder and read the content of the email. I hope (don't know how yet) to parse the body to extract a URL from it. However, the body of my email and other messages I've tried it on keeps returning empty.
$ol = New-Object -ComObject Outlook.Application
$ns = $ol.GETNAMESPACE("MAPI")
$inbox = $ns.GetDefaultFolder([Microsoft.Office.Interop.Outlook.OlDefaultFolders]::olFolderInbox)
$inbox.Items($x).Body
# returns nothing
Same result for .HTMLBody and .RTFBody.
Possibly related is that SenderName is blank too. Is it possible that have a corporate IT policy that prevents me from seeing my own message metadata? I'm exploring Powershell because they've disabled VBA in Outlook already.
We would like to query our Exchange server for emails based on (for example) the Subject field. Not from a specific address or to a specific address, but rather all emails "that went through the server" and the term X appeared in the subject.
Preferably some standard way like REST / SOAP and so on with HTTPS. Thanks.
You have two options I think, at least with powershell. First and fastest is to do a messagetrace using get-transportservice | get-messagetrackinglog to see what messages have been received and sent.
https://technet.microsoft.com/en-us/library/aa997573(v=exchg.160).aspx
Other would be to search every mailbox for messages conforming to a pre-set filter. You could use get-mailbox | search-mailbox for that.
https://technet.microsoft.com/en-us/library/dd298173(v=exchg.160).aspx
eDiscovery is the most common method you would use to do that https://support.office.com/en-us/article/eDiscovery-in-Office-365-143b3ab8-8cb0-4036-a5fc-6536d837bfce . You can use ediscovery is EWS (SOAP) https://msdn.microsoft.com/en-us/library/office/jj190897(v=exchg.150).aspx the REST API's in Office365 also allow you to search at the folder level https://msdn.microsoft.com/office/office365/APi/mail-rest-operations
Currently, each day my business needs to send and encrypted email using MS Outlook. The process works, but obviously the whole 'doing it every day thing' sucks. I've tried looking up ways to automate the process which has helped me solve the surrounding processes, but i still can't find anything, or whip up anything myself which will handle the email side. The flow of events are;
Receive
Encrypted email is received
Email is opened and attachment is dragged to UNC share 1 (repeated for each email recieved)
Attachment is picked up and processed by surrounding script
Send
Browse UNC share 2
Copy 1 of x files to a new email
Set subject as full file name
Select email to be signed/encrypted in top ribbon
Send email and repeat for each file in UNC share 2
I can get emails to send with attachment via powerhsell and by using S/MIME, but once I combine the two I get stuck and the script turns to rubble :(
Any help at all would be greatly appreciated
If I'm not mistaken, Powershell can load and use .NET assemblies, correct? (I'm not a powershell user, so my knowledge is limited).
Given that, I would recommend taking a look at using the MimeKit and MailKit libraries.
Check out the MimeKit README for some examples on how to use the S/MIME API's.
MimeKit comes with a WindowsSecureMimeContext which you might be able to use out of the box, but that depends on where your private keys and certificates are stored. If they aren't in the X509Store, then you could use the TemporarySecureMimeContext and simply load the certificate(s) and private key(s) into that and use it.
Got a similar problem and here's my solution so far, still testing:
$Outlook = New-object -ComObject Outlook.Application
$Mail = $Outlook.CreateItem(0)
$Mail.To = "me#company.tld"
$Mail.Subject ="Test"
$Mail.Body ="Test Body"
# 0 = nothing, 1 = encrypt, 2 = sign, 3 = both!
$PR_SECURITY_FLAGS = "http://schemas.microsoft.com/mapi/proptag/0x6E010003"
$Mail.PropertyAccessor.SetProperty($PR_SECURITY_FLAGS, 3)
$Mail.Send()
If Outlook is running, everything works fine. But when I start Outlook afterwards, I will find the created Mail in the Outbox without encryption and not signed.
Without Outlook running, the Code would produce an "InvokeMethodOnNull"-Error. Putting a $Mail.Display() before the SetProperty()-Part would take care of that and the buttons seem to be checked in the opening E-Mail, but the result will be the same: Start Outlook and your mail is in Outbox without encryption and not signed.
I use powershell to send emails from Outlook (complete automatic process). This work perfectly for the default mailbox. I have a lot of restrictions in the development network and can't use any software other than Outlook and powershell.
My question is: Is there a method to send email from a different account in outlook, using powershell
(in my Outlook I have three accounts A, B and C), even if i have one of the as predetermined.
The code that I use is this.
$o = New-Object -com Outlook.Application
$mail = $o.CreateItem(0)
$mail.importance = 2
$mail.subject = "SUBJECT"
$mail.body = "BODY"
$mail.To = "email001#xx.com;"
$mail.Send()
Is there a property I can set to make the email origin to be B or C, and not the predetermined A.
You need to set the SendUsingAccount property of the MailItem class which allows to set an Account object that represents the account under which the MailItem is to be sent. For example:
Sub SendUsingAccount()
Dim oAccount As Outlook.account
For Each oAccount In Application.Session.Accounts
If oAccount.AccountType = olPop3 Then
Dim oMail As Outlook.MailItem
Set oMail = Application.CreateItem(olMailItem)
oMail.Subject = "Sent using POP3 Account"
oMail.Recipients.Add ("someone#example.com")
oMail.Recipients.ResolveAll
oMail.SendUsingAccount = oAccount
oMail.Send
End If
Next
End Sub
Be aware, Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution. Read more about that in the Considerations for server-side Automation of Office article.
I have incoming email set up for SharePoint 2010, and am sending forms from InfoPath using that method, with SMTP server set up on the SharePoint Server machine. It seems easier than elevating the permissions of an anonymous user with the InfoPath code-behind option. I also tried a custom method of sending the emails but was unable to find a way to send the form data along with the email message using the InfoPath 2010 code-behind option. So, I found another way, using the advice from SharePoint UK's website.
My problem is that while removing the x-mailer header actually solved my problem regarding whole email messages, it did not allow the attached form data to be sent to the library. The message would be imported and then just disappear if I did not have the "Save original e-mail" setting enabled. Inspecting messages in the drop folder I found they had a content type of "multipart/related" and if I edited them with NotePad++ I could change that to "multipart/mixed" and the attached form data would then be imported as desired.
So I went about trying to modify the VB Script to make this happen BUT now nothing happens with the script at all. Clearly I'm doing something wrong with it and VBScript really isn't my area of expertise. Maybe it's just not possible to edit those fields or maybe I need to attack it from a different angle. How can I get my VBScript to edit the content type for these emails?
CODE:
Set shell = CreateObject("WScript.Shell")
shell.LogEvent 4, "starting mail filter"
if instr(iMsg.Fields("urn:schemas:mailheader:content-type"), "related") > 1 then
Dim logMsg = "Mail Type: " & iMsg.Fields("urn:schemas:mailheader:content-type")
Dim tempType = Replace(iMsg.Fields("urn:schemas:mailheader:content-type"), "related", "mixed")
shell.LogEvent 4, iMsg.Fields("urn:schemas:mailheader:content-type")
iMsg.Fields.Delete("urn:schemas:mailheader:content-type")
iMsg.Fields.Item("urn:schemas:mailheader:content-type") = tempType
iMsg.Fields.Update
shell.LogEvent 4, iMsg.Fields("urn:schemas:mailheader:content-type")
end if
shell.LogEvent 4, "end mail filter"
iMsg.DataSource.Save
EventStatus = 0
I looked into this in greater detail and found that the content-type property of an email message is one of the many that is read-only using this particular vbscript library. So, I would have to find some other way of editing the file, and the work involved is more than what it would take to find an alternate solution that skipped email altogether. Therefore, I am abandoning the plan of using email in this case. If you take something away from this, let it be that there are read-only properties for the mail message object in this script.