Direct Send from PS to O365

Running into problems trying to configure a Direct Send from PS to my O365 tenant. I’m guessing a lot of folks here also run 365, so I thought I might ask here for pointers.

PS c:\temp> Send-MailMessage -From -To Me@MyDomain.Com -Subject $Subject -Body $Body `
-Port 25 -UseSsl -SmtpServer "<DomainName>"

Send-MailMessage : Unable to connect to the remote server
At line:1 char:1
+ Send-MailMessage -From "" -To "" ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException
    + FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage

It’s the same thing if I use port 25 or 587, and if i send to/from a distribution list or my personal address. I can nslookup the SmtpServer name, but can’t establish a connection.

I’ve also tried creating a Connector in 365 for PowerShell to send to, but - no dice. Any ideas on what you guys would check next/make sure is correct?


EDIT: Oh - and also happens regardless of whether -UseSsl is present.

If it’s always coming from the same network, I usually set up an IIS SMTP server to relay. It’s a lot easier to get it connecting to O365 and then you can send it simply from PS or wherever. You can allow specific IPs, hosts, users, or the entire subnet. This is also a life saver for dumb scanners, phone systems, etc that may not support TLS or specific ports. You can use user authentication from the smtp relay or what I prefer, SPF/send connector handled auth. Then you can send from any email on your tenant, whether licensed or not, as long as it’s valid.

Option 3 on this page is what I was referring to.

Here is some info on SMTP relay