Answer the question
In order to leave comments, you need to log in
Why is an email not being sent from PowerShell?
Good afternoon!
There is this script:
$serverSmtp = "smtp.yandex.ru"
$port = 465
$From = "[email protected]"
$To = "[email protected]"
$subject = "Письмо"
$user = "mylogin"
$pass = "mypassword"
#Создаем экземпляр класса
$mes = New-Object System.Net.Mail.MailMessage
#Формируем данные для отправки
$mes.From = $from
$mes.To.Add($to)
$mes.Subject = $subject
$mes.IsBodyHTML = $true
$mes.Body = "<h1>Тестовое письмо</h1>"
#Создаем экземпляр класса подключения к SMTP серверу
$smtp = New-Object Net.Mail.SmtpClient($serverSmtp, $port)
#Сервер использует SSL
$smtp.EnableSSL = $true
#Создаем экземпляр класса для авторизации на сервере яндекса
$smtp.Credentials = New-Object System.Net.NetworkCredential($user, $pass);
#Отправляем письмо
$smtp.Send($mes)
Исключение при вызове "Send" с "1" аргументами: "Время ожидания операции истекло."
строка:30 знак:1
+ $smtp.Send($mes)
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SmtpException
Answer the question
In order to leave comments, you need to log in
Try changing the port to 587. Port 465 for SSL is marked as Deprecated, perhaps Yandex cut it out.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question