Send Email Using PowerShell Script

Welcome to an article on How to Send Email using PowerShell Script.

Sometimes as per our requirement, we need to send email in a process when our PowerShell script executes so we don’t need an external tool to do that. You can send emails using PowerShell.

How? Let’s see it.

  1. Open Windows PowerShell Modules as an Administrator.

    tools

    Code

    $mymail = New-Object System.Collections.Specialized.StringDictionary
    #Add the email address of the user you want to send email to.
    $mymail.Add("to", " to@webdomain.com ")
    #Add the email address of the user you want to send email as cc.
    $mymail.Add("cc", "cc@webdomain.com")
    #Add the email address of the user you want to send email as bcc.
    $mymail.Add("bcc", "bcc@webdomain.com")
    #Add the email address of the user you want to get email from.
    $mymail.Add("from", "from@ webdomain.com ")
    #provide a subject
    $mymail.Add("subject", "This is Awesome")
    #provide a type of your content
    $mymail.Add("content-type", "text/html")
    #provide the body of your email
    $bodyText = "I am sending email using PowerShell"
    #Apply the function to send email
    [Microsoft.SharePoint.Utilities.SPUtility]::SendEmail($web, $mymail, $bodyText)


  2. Save the above code in a notepad as .ps1 file.

  3. Run the code on the Windows PowerShell Modules.

  4. The desired recipients will receive an email.

It will be so quick that you don’t take much time and effort on this, thereby saving a lot of time and effort.