I would like to change this script so that uses the smtp server: smtp.office365.com
Port 587
Encryption TLS
Username: username@yourdomain.com
Password: xxxx
###PROGRAM START###
# Invokes the Send-MailMessage function to send notification email
$splat = @{
From = 'info@info.com'
To = Get-Content -Path ( Join-Path $PSScriptRoot 'DistributionList.txt')
SmtpServer = 'smtp.server.com'
Subject = $subject
body = $MessageBody
BodyAsHtml = $true
Attachment = ( Join-Path $PSScriptRoot 'abc.pdf' )
}
Send-MailMessage @splat
###PROGRAM END###
Encryption* SendmailScripting Languages
Last Comment
oBdA
8/22/2022 - Mon
ITguy565
This should do it :
###PROGRAM START#### Invokes the Send-MailMessage function to send notification email$splat = @{ From = 'info@info.com' To = Get-Content -Path ( Join-Path $PSScriptRoot 'DistributionList.txt') SmtpServer = 'smtp.server.com' Subject = $subject body = $MessageBody BodyAsHtml = $true Attachment = ( Join-Path $PSScriptRoot 'abc.pdf' ) Port = "587"}Send-MailMessage @splat -usessl -Credential $(Get-Credential)###PROGRAM END###
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
Unlimited question asking, solutions, articles and more.
oBdA
True dat.
ITguy565
@oBdA,
Touche, I did miss one item however :)
Didn't change the smtpserver **Face to Palm**
SmtpServer = 'smtp.office365.com'
Tek Info
ASKER
Thanks @oBdA however the script produces an error message.
Send-MailMessage : Transaction Failed. The server response was: 5.2.0
STOREDRV.Submission.Exception: SendAsDeniedException. MapiExceptionSendAsDenied: Failed to process message due to a
permanent exception with message. Cannot sumit message.....
…
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ITguy565
Change
From = 'info@info.com'
to a valid e-mail address associated with the account you are attempting to authenticate through...
I would be willing to bet info@info.com is on a domain you do not own.
Tek Info
ASKER
This was changed already to a valid email, and it still does not work.
oBdA
Is the From address the same as the one you used in the credential object? If not, the account used for the credentials must be allowed to send as the From user.
Open in new window