Sending emails from Powershell

Muhammad Khan 1 Reputation point
2021-02-25T20:24:01.067+00:00

Hi there,

It is panic to send emails from Outlook to hundreds of users.

I am looking for a PowerShell script to send email to around 400 hundred external Email addresses saved in a csv file. script should take the input from csv file. my mailbox in Office365.

any help.

Exchange Online
Exchange Online
A cloud-based service included in Microsoft 365, delivering scalable messaging and collaboration features with simplified management and automatic updates.
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Lucas Liu-MSFT 6,191 Reputation points
    2021-03-01T07:50:19.287+00:00

    Hi @Muhammad Khan ,
    1.Create a CSV file in the same format as the screenshot below and fill in the recipients.
    72858-1.png

    2.If you've enabled security defaults in your organization, SMTP AUTH is already disabled in Exchange Online. Run the following command to enbale the SMTP AUTH for the specific mailbox.

    Set-CASMailbox -Identity <> -SmtpClientAuthenticationDisabled $false  
    

    3.Run the following command to make sure powershell is using TLS v1.2 and send email from specific mailbox:

    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12  
    $UserCredential1 = Get-Credential  
    Import-CSV "<Path toCSV file>" | Foreach {Send-MailMessage -To $_.EmailAddress -from <The sender email address> -Subject '<>' -Body '<>' -BodyAsHtml -smtpserver "smtp.office365.com" -usessl -Credential $UserCredential1 -Port 587}  
    

    Please noted that the Send-MailMessage cmdlet is obsolete. This cmdlet does not guarantee secure connections to SMTP servers. While there is no immediate replacement available in PowerShell, Microsoft recommend you do not use Send-MailMessage.

    For more information you could refer to: Send-MailMessage and Enable or disable authenticated client SMTP submission (SMTP AUTH) in Exchange Online


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.