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

image

#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 www.powergui.org
# This PS Script is worked by Oz Casey Dedeal all Credits goes to PowerGUI (-:
#Send an email
$FromAddress = "report@telnet25.org"
$ToAddress = "odedeal@telnet25.org"
$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")
$SMTPMessage.Attachments.Add($Attachment)
$SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer
$SMTPClient.Send($SMTPMessage)
# 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)

image

image

Oz Casey Dedeal

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

Http://smtp25.blogspot.com (Blog)

Https://telnet25.spaces.live.com (Blog)

Https://telnet25.worldpress.com (Blog)

2 comments:

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!

http://thedigitalpostman.blogspot.com/

Email archiving software said...

Very helpful script, thanks for sharing it with us!