Test email from SharePoint using PowerShell

Summary:

The following PowerShell script was written for my post on configuring TLS between SharePoint and Exchange. However, since it was buried in process, I wanted to create a separate post just sharing the script, because it will be easier to maintain and use separately when needed.

Why use a script anyway?

I find this script very useful when testing mail flow from Sharepoint since it uses the “SPUtility::SendEmail” API , sends mail, captures the correct logs and presents them by launching notepad, all from a single server.

The Script:

Example:

As you can see below the script will ask for input and you will specify the SPWeb url, E-Mail recipient, E-Mail Subject and E-Mail Body. If you enter the SP Web url incorrectly, it will keep asking. Also, if the e-mail is not sent, you will be notified on screen and NOTEPAD will pop-up with the associated ULS logs.

I hope you find this useful and thanks for reading!

-Mike

3 Comments


  1. Hello

    I’ve got a problem with my Shrapoint 2019 (on premise), and it’s outgoing mail function.
    I need SP2019 site, sends mail to a Zimbra-MTA that requires authentication and TLS encryption, and expecting smtp connection via port:587. So I put these parameters in Sharepoint Central Administration (in Outgoing Mail config page). I also set the application credential key stuff. And I have used your script.
    But that is the main problem I got, in the log.csv:
    “The remote certificate is invalid according to the validation procedure”
    So I imported the self-signed CA certificate into Trusted Root Certification Authorities, on the Sharepoint Server. But I continue to receive that error, all the time.

    Could you give me a clue?

    Thanks in advance.
    Ruben

    Reply

    1. It’s definitely a cert issue. Make sure you install the cert of the SMTP server in the trusted root authority on each sp server. Also check out CAPI2 logging.. this may help.

      Reply

Leave a Reply to Ruben DiazCancel reply