Send an email via the Send-MailMessage cmdlet anonymously
July 22, 2013 Leave a comment
If you have Powershell scripts that run as a scheduled task and if they send an email, you may notice that they actually connect using authentication to the Receive Connector in Exchange 2010.
If, however, you want the email to come from a different address such as ServerName@domain.com instead of the actual email address of the service account and do not want to give the service account an email address, you may want to get the Send-MailMessage to send anonymously and not log in.
I have found the following to work OK:
$User = “anonymous”
$PWord = ConvertTo-SecureString –String “anonymous” –AsPlainText -Force
$Creds = New-Object –TypeName System.Management.Automation.PSCredential –ArgumentList $user, $pwordSend-MailMessage -To recipient@domain.com -From sender@domain.com -Subject “Subject” -Body “Body” -SmtpServer “server” -Credentials $creds
You must be logged in to post a comment.