Author Posts

April 12, 2018 at 12:55 pm

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

Whether the same can be done through SMTP without Authentication ?

April 12, 2018 at 1:35 pm

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