Mail Merge Automate through Powershell

This topic contains 1 reply, has 2 voices, and was last updated by  Olaf Soyk 3 months, 1 week ago.

  • Author
  • #98599

    Lakshmana Shiva

    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.Subject = $EmailSubject
    $Mail.From = ""
    $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"


    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: (:) [ForEach-Object], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.PowerShell.Commands.ForEachObjectCommand

    Whether the same can be done through SMTP without Authentication ?

  • #98601

    Olaf Soyk

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

You must be logged in to reply to this topic.