Example1
# You must have Site Collection Access to use following process.
function SendEmail($requestor)
{
try
{
$emailTo = $requestor
$emailSubject = "Test"
$emailBody = "Hi,This is a Test Email."
$emailUser = "yourEmail@myDomain.com"
$emailPwd = "pass@123"
Send-PnPMail -To $emailTo -Subject $emailSubject -Body $emailBody -From $emailUser -Password $emailPwd
Write-output "Email sent: Successful!"
}
catch
{
#known suppression
Write-output "Email sent: Failed! Reason:"$_.Exception.Message.ToString()
}
}
SendEmail("myEmail@myDomain.com")
Example 2
# Relay emailID example.
$smtp = new-object Net.Mail.SmtpClient("relay-mailbox.com") #Dns name or IP
$smtp.Send("fromEmail@myDomain.com", "toEmail@myDomain.com", "PowerShell Email", "This is a email from powershell")
# You must have Site Collection Access to use following process.
function SendEmail($requestor)
{
try
{
$emailTo = $requestor
$emailSubject = "Test"
$emailBody = "Hi,This is a Test Email."
$emailUser = "yourEmail@myDomain.com"
$emailPwd = "pass@123"
Send-PnPMail -To $emailTo -Subject $emailSubject -Body $emailBody -From $emailUser -Password $emailPwd
Write-output "Email sent: Successful!"
}
catch
{
#known suppression
Write-output "Email sent: Failed! Reason:"$_.Exception.Message.ToString()
}
}
SendEmail("myEmail@myDomain.com")
Example 2
# Relay emailID example.
$smtp = new-object Net.Mail.SmtpClient("relay-mailbox.com") #Dns name or IP
$smtp.Send("fromEmail@myDomain.com", "toEmail@myDomain.com", "PowerShell Email", "This is a email from powershell")
No comments:
Post a Comment
Your feedback is always appreciated. I will try to reply to your queries as soon as time allows.Please don't spam,spam comments will be deleted upon reviews.