Mail Merge Automate through Powershell

I am trying this mail as an example

$DataSource = “C:\mailmerge\users.csv”
$EmailSubject = “How to Setup Email”

Import-CSV $DataSource | Foreach-Object {
$ol = New-Object -comObject Outlook.Application
$Mail = $ol.CreateItem(0)
$Mail.Recipients.Add($.EMAIL)
$Mail.Subject = $EmailSubject
$Mail.From = “test@amazon.com
$Mail.To = "$($
.“Name”)"
$Mail.HTMLBody = “”
$Mail.HTMLBody += “$($.FIRSTNAME) $($.LASTNAME),”
$Mail.HTMLBody += “The attached directions will guide you through setting up your email account. Your username and password are as follows:”
$Mail.HTMLBody += “If you have any issues installing, please contact support”
$Mail.Send()
}

Error

Foreach-Object : There must be at least one name or contact group in the To, Cc, or Bcc box.
At line:4 char:27

  • Import-CSV $DataSource | Foreach-Object {
  •                     ~~~~~~~~~~~~~~~~
    
    • CategoryInfo : OperationStopped: (:slight_smile: [ForEach-Object], COMException
    • FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.PowerShell.Commands.ForEachObjectCommand

Whether the same can be done through SMTP without Authentication ?

Why don’t you use the cmdlet made for sending mails Send-MailMessage?