Good day.

There is Exchange 2013, a terminal server with users and the need to send mail to external addresses from the terminal using the PS script. At the same time, it is extremely reluctant to force Exchange to send messages from the terminal only with IP authorization.

Tell me how to log in to the exchange server with the credentials with which the user logged on to the terminal server?

  • Give at least a piece of the script that sends mail. It is not clear how you do it, and what exactly the problem is. - n01d
  • Tried to do with the help of Send-MailMessage and Smtp.Send, but the authorization does not pass automatically - Artem.D

2 answers 2

send-mailmessage -to "to@todomain.ru" -from "from@fromdomain.ru" -subj ect "Test mail" -SMTPServer nameserver

Also in the same cmdlet, you can specify the credits, if the machines are in the domain, then NTLM authentication will be used and it will not be necessary. If not in the domain - check

  • Thanks for the answer. Everything is in the domain, the account has a box, I try to send it from it. But in the case described by you, the authorization fails and I get "5.7.1 Unable to relay". - Artem.D
  • try -Credential (get-credential) to add to the team and enter your credentials as you log in to the cas-e SMTPServer - the address of the cas server, not the edge - Leonid Lapshin
  • 5.7.1 Unable to relay - well, maybe you need to check the settings, who is allowed to relay? - n01d

Such an error may occur if the sending is made on behalf of the server. Try to give the server the right to send on behalf of the user, and in the properties of the server account fill in the UserPrincipalName of the form <server name> @ <domain name>.