Sending email from a PC error

jzrobbie
jzrobbie used Ask the Experts™
on
Hi,

I was trying to send emails through powershell on a computer PC01. and received error message blow
"InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException"

I also tried to run the same script on another computer PC02 in the same subnet. it worked.

Both PCs can telnet to the smtp server on 25 successfully.

I have also tried to use ISP smtp to send email which was the same result PC01 didn't work with the same error. PC02 worked.
I checked the even log, no outstanding errors or warnings found.
I have also tried to turned off firewall and antivirus program without luck (which shouldn't be the issue as I can telnet to port 25 on the smtp server)
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
have you come across this? same issue.

https://social.technet.microsoft.com/Forums/ie/en-US/7242541e-5722-4064-86bf-a108daf8711a/sendmail-powershell-issues?forum=winserverpowershell

also, can you test if you are able to submit the email using telnet...

telnet smtp.domain.com 25
ehlo mydomain.com
mail from:testu@mydomain.com
rcpt to:recipient@theirdomain.com
data
This is a test.
.
quit

https://technet.microsoft.com/en-us/library/aa995718(v=exchg.65).aspx
ste5anSenior Developer

Commented:
hmm, use better exception handling and output the exception message and when available also the inner exceptions. Something like

try {
    #Send e-mail code..
}
catch {
    Write-Host $_.Exception.Message
    if ($_.Exception.InnerException) {
        Write-Host $_.Exception.InnerException.Message
    }
}

Open in new window

Author

Commented:
Hi ste5an,

I have tried your code. And received similar error
+ CategoryInfo          : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpExcept
   ion
    + FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage
ste5anSenior Developer

Commented:
Some kind SMTP of setup error. First thing after rereading:

PORT 25???? This should be closed. And you should use 587/TCP (Message Submission for Mail), cause you're acting as MUA.

Then I would use a network sniffer to analyze, what is happening.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial