Sunday, August 20, 2017

Command to send email from Office 365

Command to send email from Office 365


 $EmailFrom = “myaccount@domain.com”

$EmailTo = “emailaddress@domain.com”

$Subject = “Test from O365 SMTP”

$Body = “Test from O365 SMTP Authentication”

$SMTPServer = “smtp.office365.com”

$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)

$SMTPClient.EnableSsl = $true

$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(“myaccount@domain.com”, “*****”);

$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)

2 comments: