Direct Send from PS to O365

Welcome Forums General PowerShell Q&A Direct Send from PS to O365

Viewing 2 reply threads
  • Author
    Posts
    • #231979
      Participant
      Topics: 6
      Replies: 17
      Points: 132
      Helping Hand
      Rank: Participant

      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 [email protected] -To [email protected] -Subject $Subject -Body $Body `
      -Port 25 -UseSsl -SmtpServer "<DomainName>-com.mail.protection.outlook.com"
      
      Send-MailMessage : Unable to connect to the remote server
      At line:1 char:1
      + Send-MailMessage -From "[email protected]" -To "[email protected]" ...
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + 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.

      • This topic was modified 1 month, 2 weeks ago by mitchvh05.
    • #231985
      Participant
      Topics: 3
      Replies: 431
      Points: 1,533
      Helping Hand
      Rank: Community Hero

      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.

    • #231988
      Participant
      Topics: 3
      Replies: 431
      Points: 1,533
      Helping Hand
      Rank: Community Hero
Viewing 2 reply threads
  • You must be logged in to reply to this topic.