# Bulk email failure

**URL:** <https://forums.powershell.org/t/bulk-email-failure/11295>\
**Category:** PowerShell Help\
**Created:** [September 10, 2018, 8:40am UTC](https://forums.powershell.org/t/bulk-email-failure/11295 "2018-09-10T08:40:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kyle-lentz88](https://avatars.discourse-cdn.com/v4/letter/k/6bbea6/32.png) [@kyle-lentz88](https://forums.powershell.org/u/kyle-lentz88)\
**Post date:** [September 10, 2018, 8:40am UTC](https://forums.powershell.org/t/bulk-email-failure/11295/1 "2018-09-10T08:40:30Z")

</div>

Good Morning,

I am volunteering to help a school create a bulk email tool so they can send emails directly to all via powershell ise, Im sorry if this is a duplicate issue, I tried searching for an answer.

THIS IS CURRENTLY SET UP TO JUST SEND TO ONE PERSON AND IS NOT SET UP TO RUN OFF OF CSV, IM STILL IN THE TESTING PHASE

here is my current code:

```
## Written 5/17/18 ##Dudzy

Write-Host "=======================================================================" -ForegroundColor Green
Write-Host "============================= Email tool ==============================" -ForegroundColor Green
Write-Host "=======================================================================" -ForegroundColor Green

#Menu Actions Below
do
{
#1 send weekend update
$SMTPServer = "smtp.gmail.com"
$SmtpServerPort = "587"

#Desktop Path
$DesktopPath = [Environment]::GetFolderPath("Desktop")

#line items of order
$Principal = read-host -Prompt 'Principal'
$Preschool = read-host -Prompt 'Pre-School'
$first = read-host -Prompt '1st Grade'
$second = read-host -Prompt '2nd Grade'
$third = read-host -Prompt '3rd Grade'
$forth = read-host -Prompt '4th Grade'
$fifth = read-host -Prompt '5th Grade'
$sixth = read-host -Prompt '6th Grade'
$seventh = read-host -Prompt '7th Grade'
$eighth = read-host -Prompt '8th Grade'
$sister = read-host -Prompt 'Sister Nancy'
$Father = read-host -Prompt 'Father'
$sports = read-host -Prompt 'Sports'
$to = read-host -Prompt 'To'
$from = "EMAIL ADDRESS HERE"

#Subject
$Subject = "Weekend Update"

#Email Body
$EmailBody = @"

Hello from Holy Trinity School

Weekend Update:

From the Principal: $Principal
Pre-School: $preschool
1st Grade: $first
2nd Grade: $second
3rd Grade; $thrid
4th Grade: $forth
5th Grade: $fifth
6th Grade: $sixth
7th Grade: $seventh
8th Grade: $eighth
Sister Nancy: $sister
From Father: $father
Sports: $sports

"@

#Sending Approval Email
Send-MailMessage -SmtpServer "smtp.gmail.com" -To $To -From $from -Subject "$subject" -Body "$EmailBody" -BodyAsHtml -Priority High -ErrorAction Stop
}
Write-host "emails sent"
pause
until ($input -eq 'q')
```

Here is the error im getting **(however I cannot figure out to fix** **STARTTLS)**:  
Send-MailMessage : The SMTP server requires a secure connection or the client  
was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS  
command first. 7-v6sm6360408iou.36 - gsmtp  
At F:\HTS Email tool\email toolbox.ps1:65 char:1

- Send-MailMessage -SmtpServer “[smtp.gmail.com](http://smtp.gmail.com)” -To $To -From $from -S …
- 

```auto

```

- CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:Smtp  
Client) [Send-MailMessage], SmtpException
- FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMa  
ilMessage

&nbsp;

---

<div class="post-metadata">

**Author:** ![bdevogt](https://avatars.discourse-cdn.com/v4/letter/b/eada6e/32.png) [@bdevogt](https://forums.powershell.org/u/bdevogt)\
**Post date:** [September 10, 2018, 9:11am UTC](https://forums.powershell.org/t/bulk-email-failure/11295/2 "2018-09-10T09:11:12Z")

</div>

This is how I normally send mail

```
#region Mail

$login = ""
$password = "" | Convertto-SecureString -AsPlainText -Force
$credentials = New-Object System.Management.Automation.Pscredential -Argumentlist $login,$password
$smtpServer = "smtp.outlook.com"
$smtpFrom = ""
$smtpTo = ""
$MailSubject = ""

#############
#Send Email
Send-MailMessage -to $smtpTo -from $smtpFrom -subject $MailSubject -credential $credentials -body $OutFull -SmtpServer $smtpServer -Priority Normal -UseSsl

sleep 5
#endregion
```

&nbsp;

Use -usessl and authenticate

&nbsp;

---

<div class="post-metadata">

**Author:** ![kyle-lentz88](https://avatars.discourse-cdn.com/v4/letter/k/6bbea6/32.png) [@kyle-lentz88](https://forums.powershell.org/u/kyle-lentz88)\
**Post date:** [September 10, 2018, 9:36am UTC](https://forums.powershell.org/t/bulk-email-failure/11295/3 "2018-09-10T09:36:48Z")

</div>

updated, I have had a few tips, here is where I am at now:

you are correct, I had UseSSL missing, however once I input it, I now have a new error, here is the updated code

&nbsp;

Thank you all for the help but still not there yet

```
## Written 5/17/17 ##Dudzy

Write-Host "=======================================================================" -ForegroundColor Green
Write-Host "============================= Email tool ==============================" -ForegroundColor Green
Write-Host "=======================================================================" -ForegroundColor Green

#Menu Actions Below

#1 send weekend update
$login = ""
$password = "" | Convertto-SecureString -AsPlainText -Force
$credentials = New-Object System.Management.Automation.Pscredential -Argumentlist $login,$password
$SMTPServer = "smtp.gmail.com"

#Desktop Path
$DesktopPath = [Environment]::GetFolderPath("Desktop")

#line items of order
$Principal = read-host -Prompt 'Principal'
$Preschool = read-host -Prompt 'Pre-School'
$first = read-host -Prompt '1st Grade'
$second = read-host -Prompt '2nd Grade'
$third = read-host -Prompt '3rd Grade'
$forth = read-host -Prompt '4th Grade'
$fifth = read-host -Prompt '5th Grade'
$sixth = read-host -Prompt '6th Grade'
$seventh = read-host -Prompt '7th Grade'
$eighth = read-host -Prompt '8th Grade'
$sister = read-host -Prompt 'Sister Nancy'
$Father = read-host -Prompt 'Father'
$sports = read-host -Prompt 'Sports'
$to = read-host -Prompt 'To'
$from = "Email here"

#Subject
$Subject = "Weekend Update"

#Email Body
$EmailBody = @"

<font color="335bff">Hello from Holy Trinity School

<p class="small">
Weekend Update:

From the Principal: $Principal
Pre-School: $preschool
1st Grade: $first
2nd Grade: $second
3rd Grade; $thrid
4th Grade: $forth
5th Grade: $fifth
6th Grade: $sixth
7th Grade: $seventh
8th Grade: $eighth
Sister Nancy: $sister
From Father: $father
Sports: $sports

"@

#Sending Approval Email
Send-MailMessage -to $To -from $From -subject $Subject -credential $credentials -body $EmailBody -SmtpServer $smtpServer -Priority Normal -UseSsl
pause
```

New error **(I am not sure how to create a secure connection)**:  
Send-MailMessage : The SMTP server requires a secure connection or the client was not  
authenticated. The server response was: 5.5.1 Authentication Required. Learn more at  
At F:\HTS Email tool\email toolbox.ps1:67 char:1

- Send-MailMessage -to $To -from $From -subject $Subject -credential $c …
- 

```auto

```

- CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClien  
t) [Send-MailMessage], SmtpException
- FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMes  
sage

---

<div class="post-metadata">

**Author:** ![bdevogt](https://avatars.discourse-cdn.com/v4/letter/b/eada6e/32.png) [@bdevogt](https://forums.powershell.org/u/bdevogt)\
**Post date:** [September 11, 2018, 2:52am UTC](https://forums.powershell.org/t/bulk-email-failure/11295/4 "2018-09-11T02:52:23Z")

</div>

Sorry don’t have an Gmail account so I cannot test this.

But it tells you that you are trying to send without the proper authentication.

&nbsp;

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [September 11, 2018, 8:56am UTC](https://forums.powershell.org/t/bulk-email-failure/11295/5 "2018-09-11T08:56:12Z")

</div>

Yeah, you have to BOTH use a secure connection AND provide valid credentials to the server. It can’t just “inherit” your Windows logon credentials for an SMTP connection. You’ll need to see what kind of credential format Gmail wants, and there’s no guarantee their service is compatible with the kind of credential Send-MailMessage can provide.

Honestly, Gmail _hates_ being used as a mail relay; you may check to ensure your plan even permits you to do this because if it doesn’t, they’ll shut you down.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:34pm UTC](https://forums.powershell.org/t/bulk-email-failure/11295/6 "2024-05-16T20:34:30Z")

</div>


