The following Powershell script works on my Windows Server 2012:
send-mailmessage -from "[email protected]" -to "[email protected]" -Subject "test" -Body "test body" -smtpserver myhostip -credential "mydomain\myuser" When I execute it, a window appears that prompts for the password of the specified user. I enter the password and the e-mail is sent.
However, the following script does not work:
$smtp = New-Object Net.Mail.SmtpClient("myhostip") $smtp.usedefaultcredentials = $false $smtp.enablessl = $false $smtp.credentials = new-object net.networkcredential("myuser", "mypassword", "mydomain") $smtp.send("[email protected]", "[email protected]", "test", "test body") It results in the error message
Exception calling "Send" with "4" argument(s): "Mailbox unavailable. The server response was: 5.7.1 <[email protected]>... Relaying denied. IP name lookup failed [ip-address-of-my-web-server]" What's the difference? How can I get the second script to work?
fromaddress had one-character missing in theSmtpClientversion of the script. THANK YOU!!