Send Mail with Outlook


posted by brima
11-17-2008

Downloads: 614
File size: 429 B
Views: 10,212

Embed
Send Mail with Outlook
  1. $ol = New-Object -comObject Outlook.Application 
  2. $mail = $ol.CreateItem(0) 
  3. $Mail.Recipients.Add("XXX@YYY.ZZZ"
  4. $Mail.Subject = "PS1 Script TestMail" 
  5. $Mail.Body = " 
  6. Test Mail 
  7. " 
  8. $Mail.Send() 
  9.  
  10. # you can use this for HTML-Mails 
  11. # $Mail.HTMLBody = "<HTML><HEAD>Text<B>BOLD</B>  <span style='color:#E36C0A'>Color Text</span></HEAD></HTML>" 
  12. # you can use this for attache a file 
  13. # $Mail.Attachments.Add("D:\scripte\ol.txt") 

This script using Outlook for send the eMail.

Comments

Tobias Weltner wrote re: Send Mail with Outlook
on 11-17-2008 5:50 AM

Works perfectly.

Outlook opens a lot of warning dialogs though.

is there a way to work around them, or would I simply have to manually grant access for some time?

brima wrote re: Send Mail with Outlook
on 11-17-2008 8:47 AM

Hi Tobias,

My Outlook not open warning dialogs.

Active Directory: Windows Server 2003 SP2

eMail Server: Exchange Server 2007

Client: Outlook 2007 SP1

Userpermissions: Domain User

Best regards

brima

Aleksandar wrote re: Send Mail with Outlook
on 11-17-2008 9:14 AM

$mail = $ol.CreateItem(0) triggers first warning:

A program is trying to access e-mail addresses you have stored in Outlook. Do you want to allow this?

If this is unexpected, it may be a virus and you should choose "No".

I'm using Outlook 2003 SP2.

brima wrote re: Send Mail with Outlook
on 11-17-2008 1:12 PM

Ok, i have it now try on a other system with Outlook2007SP1 and a POP3 Account. Here i got also warning messages.

But in the domain environment are no warnings.

sertrain wrote re: Send Mail with Outlook
on 11-19-2008 8:16 AM

1..50 | ForEach-Object {

$ol = New-Object -comObject Outlook.Application

   $mail = $ol.CreateItem(0)

   $Mail.Recipients.Add("name@domain.com")

   $Mail.Subject = "PS1 Script TestMail$_"

   $Mail.Body = "

   Test mail

   "

   $Mail.Send() }

but so will send 50 messages

Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.