Install ADFS on Azure VM step by step

How to Send Email from O365 Mailbox using PowerShell without using SMTP Relay

How to Send email using PowerShell from your own mailbox?

In this post, I will describe how we can send email using our own mailbox from PowerShell Command Line.

This could be useful where you need to schedule a scripted report and the SMTP relay is not yet available, this method can also be used to send email from other messaging providers like Gmail etc.

Well, sending email using PowerShell is pretty straightforward, this method requires you to authenticate with a service provider, we will use the SSL method to send the secure email.

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 -Port 587

Comments