I'm using the Send-MailMessage function in Powershell v2.0 I'm using variables for the attachments as there will not always be attachments being sent. If there are no attachments (file locations) in the variables, I get an error otherwise it works. How I can I setup the Send-MailMessage function to output attachments and at other times not without it failing.
Send-MailMessage -BodyAsHtml –From Monitoring@CorporateActions -Priority $Priority –To "[email protected]" -Attachments $IDCSwiftLogFileAttachment,$SecurityLogFileAttachment, $ClientTypeLogFileAttachment –Subject “Corporate Actions Overnight Processing” –Body "<b><u> Download Status: </u></b> <br><br> $SWIFTDownloadErrorMessage $SecurityDownloadErrorMessage $ClientDownloadErrorMessage $HoldingDownloadErrorMessage $CLISLOOKDownloadErrorMessage $SWIFTDownloadSuccessMessage $SecurityDownloadSuccessMessage $ClientDownloadSuccessMessage $HoldingDownloadSuccessMessage $CLISLOOKDownloadSuccessMessage <b><u> X-Gen Processing Status: </u></b> <br><br> $SWIFTXGenNoInputMessage $SecurityXGenNoInputMessage $ClientXGenNoInputMessage $HoldingXGenNoInputMessage $CLISLOOKXGenNoInputMessage $IDCSwiftXGenSuccessMessage $SecurityXGenSuccessMessage $ClientXgenSuccessMessage $HoldingXgenSuccessMessage $ClientTypeXGenSuccessMessage $IDCSwiftXgenErrorMessage $SecurityXgenErrorMessage $ClientXgenErrorMessage $HoldingXgenErrorMessage $ClientTypeXGenErrorMessage” –SmtpServer smtp.investmaster.com