Sending email from PowerShell using your own mailbox.
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 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.
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 -Port 587
Comments
Post a Comment