Simple Powershell function to send email

This is a simple powershell function that sends email. There are a series of variables (i.e. $subject) that can be placed in as a parameter instead.To use this, you should make sure that your relay server is open to the host you are running this on. Please use the questions/answ

mailer.ps1
 
 
 
 
 
3.9 Star
(18)
18,481 times
Add to favorites
2/15/2013
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • how to add credentials
    1 Posts | Last post June 12, 2018
    • Sorry. How can add user credential?
      run the file failure. the server need user credential.
      
      thanks.
      Liu Wei
  • In regard to the "To" field
    1 Posts | Last post July 23, 2014
    •  - how would i define it as function. Also how do it work as a parameter ie. does it prompt me to enter the email address ? thanks in advance
  • To
    2 Posts | Last post January 14, 2014
    • Sorry but I have not seen in your script "To" field...
    • Hi,
      
      Its a variable named $emailTo that is passed to the function as a parameter.  You could also define this within the function itself and not pass a parameter.  Does that help?
  • Attachment
    2 Posts | Last post June 17, 2013
    • Please let me know how to add attachments... and also let me know how to print attachment in Msg body.
    • You should be able to add these lines at the top:
      
      $file = "C:\temp\attachment.csv"
      $att = new-object Net.Mail.Attachment($file)
      
      And then right before the line that contains "smtp.send" add:
      
      $msg.Attachments.Add($att)
      
      This is from http://www.techrepublic.com/blog/window-on-windows/send-an-email-with-an-attachment-using-powershell/4969 if you want to have a look.