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.

橙子主题打折出售

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

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

留言板

发表回复

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

热门文章

Windows Server IIS+ARR反向代理(配置反向代理服务器) 1.概念说明:反向代理反向代理服务器位于用户与目标服务器之间,但是对于用户而言,反向代理服务器就相...WindowsServerIIS+ARR反向代理(配置反向代理服务器) 作者:Pastore Antonio
1581 浏览量
ffmpeg 生成水印 1:先要配置ffmpeg的滤镜:参考:https://www.jianshu.com/p/9d24...ffmpeg生成水印 作者:Pastore Antonio
1508 浏览量
C#中List的FindAll方法的正确打开方式 初略的介绍一种常见的List写法,这种写法在3.0以后其实是很简单的,但是在2.0左右的系统运用中还...C#中List的FindAll方法的正确打开方式 作者:Pastore Antonio
1467 浏览量
IntelliJ IDEA 代码字体大小的快捷键设置放大缩小(很实用)(图文详解) 这是在设置IntelliJIDEA...IntelliJIDEA代码字体大小的快捷键设置放大缩小(很实用)(图文详解) 作者:Pastore Antonio
1461 浏览量
Navicat Premium 12.0.22 安装与破解 一、安装  NavicatPremium12.0.22的下载链接:https://pan.ba...NavicatPremium12.0.22安装与破解 作者:Pastore Antonio
1447 浏览量