Open outlook's new email dialog with prefilled information from powershell - email

I'm trying to write a powershell script (which will run periodicaly) for opening the new email windows of outlook with "to", "subject" and "body" filled with some data.
I found a way to send mails from powershell but you have to send it from powershell. this doesn't fit the need because I have to edit the body of the mail.
$Outlook = New-Object -ComObject Outlook.Application
$Mail = $Outlook.CreateItem(0)
$Mail.To = "random.dude#email.com"
$Mail.Subject = "data for Subject"
$Mail.Body ="Example of body..."
$Mail.Send()
Basicaly what i need is a $Mail.Show() wich will open a new e-mail popup with the data pre-filled
powershell is not a requirement, it just seams able to manipulate outlook so I tried with it.

thanks to this thread, the $Mail.Show() is actually $Mail.Display()

I know this is a little late however if you add the following to your script removing your $Mail.Send() line it should open the email ready for editing:
$mail.save()
$inspector = $mail.GetInspector
$inspector.Display()

Related

Outlook PowerShell script to set Direct Replies To address

I have an automated powershell script to send alert email. Since the alert are send from a generic email.. i want people replying to the email to goto another email address say efg#outlook.com.
$Outlook = New-Object -comObject Outlook.Application
$Mail = $Outlook.CreateItem(0)
$Mail.To = "asd#outlook.com"
$Mail.Subject = "Alert Email"
$Mail.HtmlBody = $HTML
$Mail.Headers.Add("In-Reply-To", "<efg#outlook.com>")
$Mail.display()
$Mail.send()
somehow this is not working.
Managed to get it from the below
ReplyRecipientNames
$Mail.ReplyRecipientNames = "efg#outlook.com"
Firstly, MailItem object does not expose the Headers property - your script will stop rigth there.
If you want to redirect replies to a different address, use Mail.ReplyRecipients.Add("efg#outlook.com")
You can use the MailItem.SendUsingAccount property which allows setting up an Account object that represents the account under which the MailItem is to be sent. Be aware, the account should be configured in Outlook in that case. For example, here is a VBA code sample which shows how to set up the property:
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
Set oMail.SendUsingAccount = oAccount
oMail.Send
End If
Next
End Sub
For Exchange users you may also consider using the MailItem.SentOnBehalfOfName property which is represented by a string indicating the display name for the intended sender of the mail message.
But also you may be interested in the MailItem.ReplyRecipients property which returns a Recipients collection that represents all the reply recipient objects for the Outlook item. The following article which I wrote for the technical blog shows how to deal with a recipient collection, see How To: Fill TO,CC and BCC fields in Outlook programmatically for more information.

Issue related to Powershell send-mail

I am using powershell send-mail command to send mail. It is working fine. But I cant see the mail which I sent in "sent items". I can see it if I sent mail manually, but I am not able to understand why it is not visible if i sent a mail using send-mail command.
Thanks
I have a function which creates an Outlook "Draft". I do it this way so that the e-mail can be reviewed before hitting "Send". This may not work for you; perhaps you'd want to add a send command at the end. But what you describe wanting to do is probably going to need outlook available on the system which is executing the commands.
It will check to see if you have a mail profile set up first, but otherwise it's not super-robust.
Function Compose-Email {
Param ([String]$recipients, [string]$subject, [string]$body)
$reg="HKCU:\Software\Microsoft\Office\16.0\Outlook\Profiles"
$child=(Get-ChildItem -Path $reg).name
if (!((Get-ChildItem -Path $reg).name)) {
Write-Error "No Mail Profile found! Cannot compose Draft."
}
else {
$olFolderDrafts = 16
$ol = New-Object -comObject Outlook.Application
$ns = $ol.GetNameSpace("MAPI")
# call the save method to save the email in the drafts folder
$mail = $ol.CreateItem(0)
$Mail.Recipients.Add($recipients)
$Mail.Subject = $subject
$Mail.Body = $body
$Mail.save()
$mail.display()
}
}

Reading Items on Outlook Shared Tasks with Powershell?

i got a question about Shared-Tasks in Outlook.
The Shared-Tasks List is from a Microsoft Exchange Server.
$Outlook = New-Object -ComObject Outlook.Application
$OutlookTasks = $Outlook.session.GetDefaultFolder(13)
$OutlookTasks = $Outlook.session.GetDefaultFolder(13).Items
$OutlookTasks | ft Subject, Body
This shows me only my own Task in Powershell.
Subject Body
------- ----
Test Task
But i want to access a Shared-Tasks List, which is listed below from "My Tasks".
It looks like this:
Outlook View
Is there a command to go deeper into my Tasks ?

Reading MSG file from outlook via powershell .. how to get email address?

Fairly simple script at the moment I simply need to get the recipients email address out of a msg file, apparently there's not an easy way to parse it in text so I've used the following code, but I only get a name such as 'Joe Smith' when reading the message not joe.smith#mydomain.com
Any ideas?
Thanks!
$outlook = New-Object -comobject outlook.application
$msg = $outlook.CreateItemFromTemplate("c:\MyMessage.msg")
$msg | Select to
You need to access the Recipients collection and read the Recipient.Address property for the items in that collection. You also might want to use Application.Session.OpenSharedItem instead of CreateItemFromTemplate.

Powershell create outlook mail with custom voting option

I have been trying to find answers with no luck if this is possible.
Is there a way to create an outlook email with custom voting options through powershell?
My goal is to have an automated script that sends email based on a criteria and have it sent with a custom voting options so that people can respond through a voting mechanism.
Here is one way to do it by using the Outlook COM Object model.
#Open Outlook
$outlook = New-Object -ComObject Outlook.Application
#Create new Mail Message
$mail = $outlook.CreateItem(0)
$mail.To = 'user#someplace.com'
$mail.Subject = 'Test Voting'
$mail.Body = 'Test Voting Message'
#Add Voting options
$mail.VotingOptions = "Yes;No;Maybe"
#Send Message
$mail.Send()
#Exit Outlook
$outlook.Quit()