Send HTML Email and attachment Powershell

Hi Readers,Sharing a sweet code to send HTML email via powershell.Aattched is a very simple method for sending the html file contains script & html file (you can edit in MS word according to your requirment).Most of the parameters that  are required to send email are in
5 Star
10,955 times
Add to favorites
E-mail Twitter Digg Facebook
Sign in to ask a question

  • How to send email only once when it is invoked in task scheduler
    1 Posts | Last post July 14, 2019
    • Hi Vikas,
      This really is  a good tool when sending email funtion gets removed in task scheduler. But I ran into a issue, could you help me out. I did a configuration:  attach the task to a specific event(invoke the sendemail.exe to send notificaiton to me), but it just didn't stop after starting. is there any way to make it send email one time only?
  • Hi Vikas
    2 Posts | Last post April 09, 2018
    • Am taking help from your mail send ps1 while writing a script for my team, I must thank you for it
      Can you please tell me how can I send multiple files in the same email using your script?
      I tried but couldnt succeed and resist myself from asking you
    • Try:
      $attach1 = new-object Net.Mail.Attachment($attachment1) 
      $attach2 = new-object Net.Mail.Attachment($attachment2) 
  • Is it possible to Use this with File monior parameter
    3 Posts | Last post April 01, 2016
    • Hi Vikas,
      Can you tell me how can I modify this script so that it monitors a particular folder, as a new file gets created in the folder it sends a pre-formatted email with the new create file in the attachment.
    • Just check my Powershell Fast Track ebook on this gallery, you will get the idea..
    • Thanks Vikas
  • Send not a specific file
    3 Posts | Last post November 18, 2013
    • Hello,
      I need to send a file that the name contains the date(ddmmyyyy), how can I add that variable when I specify the file in the attachment?
    • Yes, but if you have to do it automatically you have to use date function so that it auto formats name based on your file name.
      $days = (get-date).adddays(-60)
      $date = get-date -format d
      # replace \ by -
      $date = $date.ToString().Replace(“/”, “-”)
    • Alternate way...
      send-mailmessage -to "" -from "" -subject "Daily Report" -body "Report attached" -Attachments "C:\reports\Report_$((Get-Date).ToString('MM-dd-yyyy')).xls" -smtpServer smtpservername
  • when i execute this , getting an error, pls help
    2 Posts | Last post September 26, 2013
    • Exception calling "Send" with "1" argument(s): "Failure sending mail."
      At E:\powershell\sendemail\sendemail\Sendemail.ps1:27 char:1
      + $smtp.Send($message)
      + ~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
          + FullyQualifiedErrorId : SmtpException
    • have you entered the SMTP server address, also does your smtp server allow you to send emails..