SMTP Email for AD with Send-MailMessage

Both versions of AD use the Microsoft Powershell’s Send-MailMessage commandlet to send outgoing emails.

SMTP email is delivered system by transferring emails from one computer’s mail transfer agent (MTA) to another until it gets delivered to the final recipient. DataSelf’s AD software uses Microsoft’s Send-MailMessage utility to send the email on the first leg of that journey.

See also https://dataself.atlassian.net/wiki/spaces/DS/pages/1118896129

SMTP Email Settings in Static Configuration File

Each DSA AD & DSA Cloud AD installation has a static (almost never changed) configuration file. The file is typically named SParms0.ps1 . .ps1 is the extension for a PowerShell script.

Settings in static configuration file to Connect to a SMTP Server

#--------- Email function parms  ------------------------------- [string] $global:SMTPServer = "Smtp.office365.com" [int]    $global:SMTPPort = 587 [bool]   $global:SMTPUseSSL = $true [string] $global:SMTPUser = xxxx@xxxxx.com   # For anonymous access set to empty string (") [string] $global:SMTPPassword = 'xxxxxxxxx'

More on the static configuration / static parms file at https://dataself.atlassian.net/wiki/spaces/DS/pages/1789657157

Send-MailMessage (PowerShell commandlet)

Microsoft documentation: Send-MailMessage - PowerShell | Microsoft Docs

Send-MailMessage Example

Send-MailMessage -From 'User01 ' -To 'ITGroup ' -Cc 'User02 ' -Bcc 'ITMgr ' ` -Subject "Don't forget today's meeting!" ` -SmtpServer 'smtp.gmail.com' -Credential domain01\admin01 -UseSsl

Send-MailMessage Syntax

Send-MailMessage [-To] <string[]> [-Subject] <string> [[-Body] <string>] [[-SmtpServer] <string>] -From <string> [-Attachments <string[]>] [-Bcc <string[]>] [-BodyAsHtml] [-Encoding <Encoding>] [-Cc <string[]>] [-DeliveryNotificationOption <DeliveryNotificationOptions>] [-Priority <MailPriority>] [-Credential <pscredential>] [-UseSsl] [-Port <int>] [<CommonParameters>]

Credentials

Not all SmtpServers require credentials - user name or username + password.

For Credentials see example 3 in send-mailmessage documentation

SMTP Accounts & Server Connection Parameters

  • The host name (URL to server)

  • The port

  • The SSL authentication

  • The account information (username, password, etc.)

Notes

  • Server identification (host name): Type the SMTP server’s unique specification. Find that information on the service provider’s web page or on a POP/SMTP server list.

  • Port: Most SMTP functions optimally on port 25, although some are compatible with 587 as well. Check your server specifications for more information.

  • Connection security: SMTP doesn’t usually include email encryption, so secure your connections using STARTTLS or SSL/TLS extensions. You may want to use a different port for encrypted messages.

Editing & Running PowerShell

Most Microsoft Windows servers and desktops include a PowerShell editor (PowerShell IDE). Powershell scripts can be run from the PowerShell IDE