How to send email using powershell in sharepoint

Advertisements
Here we can see the script,the way we can sent mail alerts using power shell

$EmailFrom = "FromEmail@domain.com"
$EmailTo = "ToEmail@domain.com"
$SMTPServer = "YourSmtpServerName"
$EmailSubject = "Enter your Subject you want"

$mailmessage = New-Object system.net.mail.mailmessage
$mailmessage.from = ($EmailFrom)
$mailmessage.To.add($EmailTo)
$mailmessage.Subject = $EmailSubject
$mailmessage.Body = "Email body"
#if we are sending any html body we have to use below line
$mailmessage.IsBodyHTML = $true
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer)
#if you want any network credentials set user name and password.
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("username", "password");
$SMTPClient.Send($mailmessage)

SharePoint Online Real Time Training Contact: JLAKSHMITULASI@GMAIL.COM
Advertisements
SHARE

lakshmitulasi Jasti

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

1 comments: