0

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?

2
  • 1
    did you try turning it all into variables and plugging the variables into the first script, wouldn't that work? Commented May 27, 2015 at 14:32
  • Duh!! The from address had one - character missing in the SmtpClient version of the script. THANK YOU!! Commented May 27, 2015 at 15:11

1 Answer 1

1

did you try turning it all into variables and plugging the variables into the first script, wouldn't that work?

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.