วิธีทดสอบอีเมลขาออกใน SharePoint โดยใช้ PowerShell
ในขณะที่แก้ไขปัญหาอีเมล SharePoint ในขั้นตอนแรก เราต้องตรวจสอบการตั้งค่าอีเมลขาออกที่ใช้บนไซต์การดูแลจากศูนย์กลางของ SharePoint นั้นถูกต้อง ดังนั้นจะทดสอบอีเมลขาออกของ SharePoint อย่างรวดเร็วได้อย่างไร นี่คือสคริปต์ PowerShell ของฉันเพื่อทดสอบอีเมลขาออกใน SharePoint 2013 หรือ 2016
วิธีที่ 1: ส่งอีเมลโดยใช้ SendEmail ของ SPUTility
เรียกเมธอด SendEmail ดั้งเดิมของ SharePoint จากคลาส SPUTility:
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)
สคริปต์ PowerShell ข้างต้นส่งอีเมลไปยังอีเมลที่ระบุและส่งกลับ "จริง" หากสำเร็จ
วิธีที่ 2: การใช้ .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)
วิธีที่ 3: การใช้ข้อความส่งเมล PowerShell 3.0
สุดท้าย ใช้ Send-MailMessage cmdlet ดั้งเดิมของ PowerShell เพื่อตรวจสอบการตั้งค่าอีเมลขาออก
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
สุดท้ายแต่ไม่ท้ายสุด เราอาจต้องตรวจสอบให้แน่ใจว่า Exchange Server หรือ SMTP ยอมรับอีเมลจากเซิร์ฟเวอร์ SharePoint
