Users: 30k; Pages Per Session: 2.5p; Avg. Session Duration: 1:35mi
Explore Tools
{Featuring Microsoft Technologies + Enterprise Data + Cloud Computing}

Troubleshooting Azure VM SQL Server Database Mail using SmtpClient class, PowerShell and SendGrid
by BF (Senior MSSQL Operations - Enterprise, Cloud, Strategy)

Check if the Server can send email via Powershell. Good for troubleshooting Database Mail to rule out the Server can send mail successfully or not.

Powershell Code:

# Create From/To Addresses:

$from = New-Object System.Net.Mail.MailAddress ""
$to = New-Object System.Net.Mail.MailAddress ""

# Create Message:
$message = new-object System.Net.Mail.MailMessage $from, $to
$message.Subject = "Using the SmtpClient class and PowerShell"
$message.Body = "This is a test mail from Powershell."

# Set SMTP Server and create SMTP Client:
$server = ""
$port = 25
$client = new-object ($server,$port)

# Specify the authentication:
$credential = Get-Credential
$client.UseDefaultCredentials = $false
$client.EnableSsl = $true;
$client.Credentials = new-object System.Net.NetworkCredential($credential.UserName,$credential.Password)

# Send the message:
" "
"Sending an e-mail message to {0} by using SMTP host {1} port {2}." -f $to.ToString(), $client.Host, $client.Port
" "

Related: SQL Server Database Mail - Success, Failure, Logs, Config