Send mail using PowerShell cmdLet.
I generally use these cmdLet to verify outgoing email settings.
- Using smtp address (Hardcoding the SMTP address)
function send-notification($subject, $detail) {
$message = New-Object System.Net.Mail.MailMessage
$message.Subject = $subject
$message.Body = $detail
$message.To.Add("recipient1@domain.com")
$message.To.Add("recipient2@domain.com")
$message.Cc.Add("cc1@domain.com")
$message.Bcc.Add("bcc1@domain.com")
$message.From = "Admin@Domain.com" # we can use sent From as $headers.Add("from", "Admin@Domain.com") also
$client = New-Object System.Net.Mail.SMTPClient -ArgumentList "192.168.0.1"
$client.Send($message)
}
$dbname = Get-SPContentDatabase -WebApplication http://servername:port
send-notification -subject "$dbname Attached" -detail "The content database $dbname has completed the database attach upgrade. Please review the logs in Central Administration as soon as possible."
2. Using Microsoft.SharePoint.Utilities.SPUtility
Updated:-
$web = Get-SPWeb -Site http://server:Port
$headers = New-Object System.Collections.Specialized.StringDictionary
$headers.Add("to", "recipient1@domain.com")
$headers.Add("to", "recipient2@domain.com")
$headers.Add("cc", "cc1@domain.com")
$headers.Add("bcc", "bcc1@domain.com")
$headers.Add("from", "SpAdmin@domain.com")
$headers.Add("subject", "Test Email Subject")
$headers.Add("content-type", "text/html")
$bodyText = "Hello how are you?"
[Microsoft.SharePoint.Utilities.SPUtility]::SendEmail($web, $headers, $bodyText)
You can check the same here also
