A
A
asdz2015-04-22 21:38:50
PowerShell
asdz, 2015-04-22 21:38:50

Why is email not being sent from powershell?

There is mail on google apps, script:

param ($subject, $body)
$EmailFrom = "[email protected]"
$EmailTo = "[email protected]"
$SMTPServer = "smtp.gmail.com"
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials=new-object Management.Automation.PSCredential “[email protected]”, (“1234567” | ConvertTo-SecureString -AsPlainText -Force)
$SMTPClient.Send($EmailFrom, $EmailTo, $subject, $body)

Mistake:
Исключение при вызове "Send" с "4" аргументами: "Серверу SMTP требовалось защищенное соединение, или подлинность клиента не была установлена. Ответ сервера: 5.5.1 Authentication Required. "

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
TomosBlack, 2015-05-30
@TomosBlack

Decision. Believe it works.

$SMTPClient.Credentials = New-Object System.Net.NetworkCredential '[email protected]', 'password'

A
Aniko, 2016-02-22
@Aniko

It's all about two-factor authentication on gmail. Somewhere since the middle of 2014, Google considers all applications that do not use two-factor authentication not secure.
The solution is as follows:
1. Enable two-factor authentication 2.
Add a password for the application in the settings on the google site (16-digit)
3. Use the generated password instead of your usual password in the application
.
I hope this is relevant to someone.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question