Sending email from a PC error

jzrobbie used Ask the Experts™

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)
Watch Question

Do more with

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

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

telnet 25
This is a test.
ste5anSenior Developer

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


Hi ste5an,

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

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