Sending Email from 0365 Mailbox using powershell


This could be useful where you need to schedule some report and the SMTP relay is not yet available

Sending email using your own mailbox
this method can also be used to send email from other messaging provider like Gmail etc.

Well sending email using PowerShell is pretty straight forward.

this method require you to authenticate with service provider we will use the SSL method to send the secure email here.

Note :

"$from" array will always be your mailbox primary Smtp, this mailbox will be auth in cloud service.



# type your mailbox userid and pass for O365

$cred = Get-Credential 
$From = $cred.username

# this would be the smpt service Server address of the service provider
$SMTPSrver ="SMTP.Office365.com"

# Edit recipent & message details here
$To =  "someone@LetsExchange.in"
$subject = "Your Email Subject"
$Emailbody =  "Your Email Body"
$attachment = "Logs.txt"                     # if you wish to attach any file in Email.


Send-MailMessage -From $from `
-To $to `
-Subject $subject `
 -Body $Emailbody `
 -SmtpServer $SMTPSrver `
 -Attachments $attachment `
 -Credential $cred -UseSsl



Comments