Using Outlook Application to Email.

Iron Contributor

Sharing Mode.

When SMTP Port is block by your firewall.



# create COM object named Outlook
Add-Type -assembly "Microsoft.Office.Interop.Outlook"
Add-Type -assembly "System.Runtime.Interopservices"
    $Outlook = [Runtime.Interopservices.Marshal]::GetActiveObject('Outlook.Application')
    # create Outlook MailItem named Mail using CreateItem() method
	$Mail = $Outlook.CreateItem(0)

	# add properties as desired
	$Mail.To = "<email address removed for privacy reasons>; <email address removed for privacy reasons>"
	$Mail.Subject = "Subject" 
	$Mail.Body = "Email Sent using PowerShell via Outlook

	Best Regards,  

	# Add Attachement

	# Send message

	# Give time to send the email
	Start-Sleep 5

	#quit and cleanup
	[System.Runtime.Interopservices.Marshal]::ReleaseComObject($Outlook) | Out-Null
    write-host "Sending Email Failed!"




0 Replies