Tek Info
asked on
Modify script to use Office365 and port 587
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###
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###
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Can the credential be embedded in the script?
@Tek Info,
oBdA's script has the credential embedded.
oBdA's script has the credential embedded.
Really it is the only difference from mine..
Not quite, -UseSsl is missing in yours as well ;)
Send-MailMessage @splat -usessl -Credential $(Get-Credential)
###PROGRAM END###
I added it to the command string rather than to the @splat
True dat.
@oBdA,
Touche, I did miss one item however :)
Didn't change the smtpserver **Face to Palm**
SmtpServer = 'smtp.office365.com'
Touche, I did miss one item however :)
Didn't change the smtpserver **Face to Palm**
SmtpServer = 'smtp.office365.com'
ASKER
Thanks @oBdA however the script produces an error message.
Send-MailMessage : Transaction Failed. The server response was: 5.2.0
STOREDRV.Submission.Except ion: SendAsDeniedException. MapiExceptionSendAsDenied: Failed to process message due to a
permanent exception with message. Cannot sumit message.....
…
+CategoryInfo :InvalidOperation: (System.Net.Mail. SmtpClient: StmtpClient) [Send-MailMessage], SmtpException
+FullyQualifiedErrorId: SmtpException, Microsfoft.Powershell.Comm ands.Send Message
Send-MailMessage : Transaction Failed. The server response was: 5.2.0
STOREDRV.Submission.Except
permanent exception with message. Cannot sumit message.....
…
+CategoryInfo :InvalidOperation: (System.Net.Mail. SmtpClient: StmtpClient) [Send-MailMessage], SmtpException
+FullyQualifiedErrorId: SmtpException, Microsfoft.Powershell.Comm
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.
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.
ASKER
This was changed already to a valid email, and it still does not work.
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