SendMail PowerShell issues!

Hello guys!

I'm trying to send an e-mail from PowerShell (Windows 2008 R2) and I keep getting this error:

Exception calling "Send" with "4" argument(s): "Failure sending mail."

At C:\path\script.ps1:14 char:12

+  $smtp.Send <<<< ($emailFrom, $emailTo, $subject, $body)

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : DotNetMethodException

 

If I try the cmdlet:

Send-MailMessage -to user1@domain.com -from user2@domain.com -body "test" -Subject "test" -SmtpServer SMTP.domain.com 

I get this error:

Send-MailMessage: Unable to read data from the transport connection: net_io_connectionclosed. At line:1 char:17

+ Send-MailMessage <<<<  -to user1@domain.com -from user2@domain.com -body "test" -Subject "test" -SmtpServer SMTP.domain.com

+ CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtepException

+ FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage

 

Any ideas?

Thanks,

Yuri

February 16th, 2011 1:39pm

1) check firewall

2) nslookup SMTP.domain.com 

3)  telnet SMTP.domain.com  25

4) try to use with -Credential

Free Windows Admin Tool Kit Click here and download it now
February 16th, 2011 1:52pm

The FireWall is down. Telnet (25) and nslookup works fine. The credential I'm seeing if it's the right one, but let's assume that is right for now (almost sure that is), any more leads?

Thank you for this initial help!!

February 16th, 2011 2:07pm

The FireWall is down. Telnet (25) and nslookup works fine. The credential I'm seeing if it's the right one, but let's assume that is right for now (almost sure that is), any more leads?

Thank you for this initial help!!

With -UseSSL ? Just try to use network monitor, it can help clarify the situation.
Free Windows Admin Tool Kit Click here and download it now
February 16th, 2011 2:27pm

As a final verification of the SMTP parameters, I would recommend following the steps in this article to send a message via telnet (http://support.microsoft.com/kb/153119).  This will give you a definitive answer that the local server can send mail to the server with the recipient and sender you specify.  Some messaging systems have a restriction on which IP Addresses can send to it and going through these steps will prove that.  If you see something like unable to relay, then you will need to talk to the messaging system administrator.

February 16th, 2011 2:52pm

just for chuckles, try it this way.

$smtp = New-Object System.Net.Mail.SmtpClient
$to = New-Object System.Net.Mail.MailAddress("to@domain.com")
$from = New-Object System.Net.Mail.MailAddress("from@domain.com")
$msg = New-Object System.Net.Mail.MailMessage($from, $to)
$msg.subject = "test"
$msg.body = "testing"
$smtp.host = "smtp.domain.com"
$smtp.send($msg)

Free Windows Admin Tool Kit Click here and download it now
February 16th, 2011 4:00pm

If this a work machine?  By some of your errors, it really seems like you may not just have a firewall, but application-level restrictions potentially.  There are some security suites that will block applications from using certain ports, and SMTP definitely being one of them..

You say telnet to port 25 works fine...  What exactly have you tried and are seeing?

February 16th, 2011 11:23pm

Hi,

 

Based on my research, the error message “Unable to read data from the transport connection: net_io_connectionclosed” means that System.net.mail was unable to find the SMTP server. This could be caused by SMTP service setting. Please check if the SMTP service is bound to a specific IP address or a dynamic IP address. Open the SMTP server properties, click General tab, see the IP Address dropdown box, set it to All unsigned and see if the issue get resolved.

 

Best Regards

Dale

Free Windows Admin Tool Kit Click here and download it now
February 17th, 2011 5:32am

Thank you!  I was having this very issue today.  Our SMTP server was cloned into a test environment and its IP address changed.

Chris

July 10th, 2015 5:54pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics