- $user = 'John'
- $ADUser = (Get-ADUser $user -Properties *)
- $Manager = (get-aduser (get-aduser $user -Properties manager).manager)
- $sRecipientAddr = "$($manager.userprincipalname); $($ADUser.mail)"
- $sMsgSubject = "Notice of closure for Incident"
- $oOutlook = New-Object -ComObject Outlook.Application
- $oMapiNs = $oOutlook.GetNameSpace("MAPI")
- $oMailMsg = $oOutlook.CreateItem(0)
- [Void]$oMailMsg.Recipients.Add($sRecipientAddr)
- $oMailMsg.Subject = $sMsgSubject
- $oMailMsg.Display()
outlook email with body and signature
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- apowershelluser
- Posts: 194
- Last visit: Fri Mar 22, 2024 4:38 am
outlook email with body and signature
Re: outlook email with body and signature
To assign the body do this:
$oMailMsg.Body = 'Hello World'
There is no method for adding a signature. To add the default signature the "Display()" must be called before the body is assigned.
$oMailMsg.Body = 'Hello World'
There is no method for adding a signature. To add the default signature the "Display()" must be called before the body is assigned.
Code: Select all
$oOutlook = New-Object -ComObject Outlook.Application
$oMapiNs = $oOutlook.GetNameSpace("MAPI")
$oMailMsg = $oOutlook.CreateItem(0)
$oMailMsg.Display()
[Void]$oMailMsg.Recipients.Add($sRecipientAddr)
$oMailMsg.Subject = $sMsgSubject
$oMailMsg.Body = 'Hello World'
- apowershelluser
- Posts: 194
- Last visit: Fri Mar 22, 2024 4:38 am
Re: outlook email with body and signature
That is not what I'm experiencing. The signature gets automatically put on there. If I add in the .body such as you did, it wipes out the signature
- apowershelluser
- Posts: 194
- Last visit: Fri Mar 22, 2024 4:38 am
Re: outlook email with body and signature
Try it like this.
Code: Select all
$recipients = 'jjones@domain.com'
$subject = 'Notice of closure for Incident'
$ol = New-Object -ComObject Outlook.Application
$ns = $ol.GetNameSpace("MAPI")
$mailItem = $ol.CreateItem(0)
$insp = $mailItem.GetInspector()
[Void]$mailItem.Recipients.Add($recipients)
$mailItem.Subject = $subject
#$mailItem.HTMLBody = ('<body><p>Hello World 3</body></p>' + $mailItem.HTMLBody)
$mailItem.Body = ('Hello World 3' + $mailItem.Body)
$mailItem.Send()
[/b]
- apowershelluser
- Posts: 194
- Last visit: Fri Mar 22, 2024 4:38 am
Re: outlook email with body and signature
Thank you! I add to add HTMLBody, but I got it
- $recipients = 'jjones@domain.com'
- $subject = 'Notice of closure for Incident'
- $ol = New-Object -ComObject Outlook.Application
- $ns = $ol.GetNameSpace("MAPI")
- $mailItem = $ol.CreateItem(0)
- $insp = $mailItem.GetInspector()
- [Void]$mailItem.Recipients.Add($recipients)
- $mailItem.Subject = $subject
- $mailItem.HTMLBody = ('Hello World' + $mailItem.HTMLBody)
- $mailItem.Display()