Logo

How to Test Outgoing Emails in SharePoint using PowerShell

photo

2024年01月22日

While troubleshooting SharePoint Email issues, as a first step, we have to check outgoing Email settings applied on the SharePoint Central Administration site are valid. So, how to test SharePoint outgoing email quickly? Here are my PowerShell scripts to test outgoing emails in SharePoint 2013 or 2016.

Method 1: Send Email using SPUtility’s SendEmail

Call the SharePoint native SendEmail method from the SPUtility class:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
#Configuration Parameters
$SiteURL="https://portal.crescent.com/ "
$Email = "salaudeen.rajack@crescent.com"
$Subject = "Test Email from SharePoint"
$Body = "Test Email Body"
 
#Get the Web
$Web = Get-SPWeb $SiteURL
 
#Send Email using SPUtility SendEmail method
[Microsoft.SharePoint.Utilities.SPUtility]::SendEmail($Web ,0,0,$Email,$Subject,$Body)


#Read more: https://www.sharepointdiary.com/2016/09/how-to-test-outgoing-emails-in-sharepoint-using-powershell.html#ixzz8PXaQKXqX

The above PowerShell script sends mail to the given email and returns “true” if successful.

how to test sharepoint outgoing email

Method 2: Using .Net SMTP Send Mail

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
#Parameters
$EmailTo = "salaudeen.rajack@crescent.com"
$Subject = "Test Email from SharePoint"
$Body = "Test Email Body"
 
#Get the outgoing Email Server settings
$SPGlobalAdmin = New-Object Microsoft.SharePoint.Administration.SPGlobalAdmin
$SMTPServer = $SPGlobalAdmin.OutboundSmtpServer
$EmailFrom = $SPGlobalAdmin.MailFromAddress
 
#Frame Email Message
$Message = new-object Net.Mail.MailMessage
$SMTP = new-object Net.Mail.SmtpClient($SMTPServer)
$Message.From = $EmailFrom
$Message.To.Add($EmailTo)
$Message.subject = $Subject
$Message.body = $Body
 
#Send the Email
$SMTP.Send($Message)


#Read more: https://www.sharepointdiary.com/2016/09/how-to-test-outgoing-emails-in-sharepoint-using-powershell.html#ixzz8PXam5fxd

Method 3: Using PowerShell 3.0 Send-Mail Message

Finally, use PowerShell’s native Send-MailMessage cmdlet to validate the Outgoing Email settings.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
#Parameters
$EmailTo = "salaudeen.rajack@crescent.com"
$EmailSubject = "Test Email from SharePoint"
$EmailBody = "Test Email Body"
 
#Get the outgoing Email Server settings
$SPGlobalAdmin = New-Object Microsoft.SharePoint.Administration.SPGlobalAdmin
$SMTPServer = $SPGlobalAdmin.OutboundSmtpServer
$EmailFrom = $SPGlobalAdmin.MailFromAddress
 
#Using PowerShell 3.0 Send-Mail Message:
Send-MailMessage -To $EmailTo -From $EmailFrom -Subject $EmailSubject -Body $EmailBody -BodyAsHtml -SmtpServer $SmtpServer -UseSsl


#Read more: https://www.sharepointdiary.com/2016/09/how-to-test-outgoing-emails-in-sharepoint-using-powershell.html#ixzz8PXauZOI2

Last but not least, We may have to ensure the exchange server or SMTP accepts Emails from SharePoint servers.

橙子主题打折出售

其实我不卖,主要是这里是放广告的,所以就放了一个
毕竟主题都没做完,卖了也是坑.

购买它
本文为原创文章,请注意保留出处!

留言板

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

热门文章

Adobe Acrobat Pro 激活 这里记录了一些AdobeAcrobat的激活教程和组件。浏览量:1,987 作者:Pastore Antonio
1830 浏览量
“sudo: apt-get:找不到命令”的解决方法 Linux系统:CentOS7原因分析:这是由于CentOS的软件安装工具不是apt-get,而是...“sudo:apt-get:找不到命令”的解决方法 作者:Pastore Antonio
1540 浏览量
一个不可思议的一天 上周五可以说是我人生中的梦魇……因为时间没安排好,为了一个10几分钟的会议,打的花了100多。然...一个不可思议的一天 作者:Pastore Antonio
1531 浏览量
Win10中使用cmd命令快速安装telnet服务 Win10中不能够使用Telnet的主要原因是由于系统默认情况下是没有安装telnet服务的,所以我...Win10中使用cmd命令快速安装telnet服务 作者:Pastore Antonio
1524 浏览量
Windows Server IIS+ARR反向代理(配置反向代理服务器) 1.概念说明:反向代理反向代理服务器位于用户与目标服务器之间,但是对于用户而言,反向代理服务器就相...WindowsServerIIS+ARR反向代理(配置反向代理服务器) 作者:Pastore Antonio
1518 浏览量