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)

4 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!

JacobHarman said...

Moreover, we are don't know whether it's the reason or the impact however Clojure programming draws in quite possibly of the savviest engineer. Perhaps this is on the grounds that as a Practical programming language rather than an Item situated language it draws in brilliant Clojure designers. It's heard again and again in the business when you get an accomplished Clojure engineer you're getting truly outstanding and the most brilliant. Without a doubt as per the UK firm, USwitch while enrolling for Clojure engineers they report "we get excellent volunteers keen on something other than creating, they are thinking past their code">> clojure developer

John Fei said...

Essay genrator are transforming the way we approach academic writing. With the click of a button, these innovative tools can generate unique and well-structured essays on a variety of topics. The essay genrator streamlines the writing process and provides a starting point for further exploration and refinement. While it should be used as a tool to assist and inspire, the creativity and critical thinking of the writer are still essential in producing a thoughtful and original essay.