I've got a single multi-role Exchange 2010 server and a need to execute a Powershell script on monthly schedule.
And i really would like to send a report via email to some local company's mailbox by the end of the task.
I created a service account with required permissions and wrote a Powershell script that's doing everything fine when run as service account - except the email report part.
Adding my Exchange server's IP to anonymous-allowed Receive connector doesn't sound right to me, maybe there is kind of best practice to do it?
Any opinion is much appreciated!
UPDATE:
As for the mail part of the script, usually i use a .NET Net.Mail.MailMessage object like this:
$SmtpServer = "exchangeserver.corp.company.com"
$Msg = New-Object Net.Mail.MailMessage
$Smtp = New-Object Net.Mail.SmtpClient($SmtpServer)
$Msg.From = "[email protected]"
$Msg.ReplyTo = "[email protected]"
$Msg.To.Add("[email protected]")
$Msg.Subject = "Monthly script execution report"
$Msg.Body = "Everything's ok, some statistics etc."
$Smtp.Send($Msg)
When i use this code the Exchange server answers with "Service unavailable". To me it makes sense since there are no Receive connectors configured. Standard Send-MailMessage
Powershell command gives the same result so the problem is not with the code, actually it works fine on non-Exchange servers.
Currently i've got three Receive connectors:
- one for external mail with FQDN mail.company.com accepting connections on port 25
- one for internal Exchange clients with FQDN exchangeserver.corp.company.com on standard SSL port 587
- and one for list of local servers who send mail via Exchange without authentication with FQDN exchangeserver.corp.company.com on port 25 (not a perfect solution and i would prefer not to add my Exchange server's IP to the list)
So i'm looking for a nice-and-secure way to make it work, thanks in advance!
The solution is quite simple, having a password for ExchangeServiceAccount as SecureString $ExchangeServicePassword variable: