Friday, June 26, 2009

Send Mail With Attachment Using PowerGUI

Here is another nice PS script made by PowerGUI and this script will sent “ attachment” along with the e-mail. You can imagine where we will be using this script, all scripts we have created within the PowerGUI can be integrated with this script and we can automatically sent attachments.

Click here to download


#Send mail with attachment Script by Oz Casey Dedeal
#Send mail with attachment Script
#Created with PowerGUI
#I cannot thank enough to PowerGUI, it is life saver (-:
#If you want your hands get dirty go download PG from
# This PS Script is worked by Oz Casey Dedeal all Credits goes to PowerGUI (-:
#Send an email
$FromAddress = ""
$ToAddress = ""
$MessageSubject = "Mailbox Size Report"
$MessageBody = "Please see the Mailbox report"
# Mail2 is my Relay Server, Change this to your own Relay Server
# Make sure port 25 is open, there is no firewall turned on, might me blocking port 25, if you are not going to run this from relay server itself
$SendingServer = "Mail2"
$SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress, $ToAddress, $MessageSubject, $MessageBody
# Make sure this directory is Valid, I used C drive and created folder called Report from my workstation
$Attachment = New-Object Net.Mail.Attachment("c:\Report\report.csv")
$SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer
# now mail is sent check your mailbox

  • You can also copy and paste the script included above table
  • Make sure port 25 is open if you are going to be using your workstation
  • Make sure from your workstation , relay is allowed to the relay server
  • Make sure you can resolve the name of the relay server
  • Make sure you created the folder on your C Drive ( change this as you wish)



Oz Casey Dedeal

MVP (Exchange)
MCSE 2003, M+, S+, MCDST
Security+, Project +, Server +

Http:// (Blog)

Https:// (Blog)

Https:// (Blog)


VA's RHD Hachi Roku said...

I'm glad you posted this, I was just pondering on the same thing a few days ago. I'm a long time Exchange admin, but new to PowerShell and scripting. I'm really enjoying learning PowerShell.

Thanks for the script!

Email archiving software said...

Very helpful script, thanks for sharing it with us!

ADV Movers said...

Best Moving Company +971 50 3605353

We are Cheap Movers in Dubai, providing best moving services at reasonable prices. Call Now for Residential and Commercial Dubai Movers +971503605353

Dubai Movers
Movers Dubai
moving services dubai
moving company
movers dubai
home movers dubai
Packer in Dubai
Local Movers
Cheap Movers in Dubai
Dubai Local Movers