PowerShell Exception calling "Send" with "1" argument(s): "Failure sending mail."
<p>I am running into the following error when running this script:</p>

<p>Exception calling "Send" with "1" argument(s): "Failure sending mail."</p>

<pre><code>#Variables to configure
$MailServer = "domain.com"
$ReportSender = "email@domain.com"
$ReportRecipient = "email@domain.com"
$MailSubject = ("yourdomain.local exchange2010 Mailbox Report for " + $MailServer + " - " + ( get-date ).ToString('yyyy/MM/dd'))

#SendEmailFunction
Function send-mailmessage
{ param($smtphost,$htmlFileName)
$smtp= New-Object System.Net.Mail.SmtpClient $smtphost
$msg = New-Object System.Net.Mail.MailMessage $ReportSender, $ReportRecipient, $MailSubject, (Get-Content $htmlFileName)
$msg.isBodyhtml = $true
$smtp.send($msg)
}

$exdata = Get-MailboxStatistics -Server $MailServer | Sort-Object TotalItemSize -descending | Select-Object DisplayName, ItemCount, TotalItemSize, Database, StorageLimitStatus

$fileName = "exchange2010Report.html"
New-Item -ItemType file $fileName -Force

# HTML start
Add-Content $fileName "&lt;html&gt;"

# HEAD start
Add-Content $fileName "&lt;head&gt;"

add-content $fileName '&lt;STYLE TYPE="text/css"&gt;'
add-content $fileName  "&lt;!--"
add-content $fileName  "td {"
add-content $fileName  "font-family: Tahoma;"
add-content $fileName  "font-size: 11px;"
add-content $fileName  "border-top: 1px solid #999999;"
add-content $fileName  "border-right: 1px solid #999999;"
add-content $fileName  "border-bottom: 1px solid #999999;"
add-content $fileName  "border-left: 1px solid #999999;"
add-content $fileName  "padding-top: 0px;"
add-content $fileName  "padding-right: 0px;"
add-content $fileName  "padding-bottom: 0px;"
add-content $fileName  "padding-left: 0px;"
add-content $fileName  "}"
add-content $fileName  "body {"
add-content $fileName  "margin-left: 5px;"
add-content $fileName  "margin-top: 5px;"
add-content $fileName  "margin-right: 0px;"
add-content $fileName  "margin-bottom: 10px;"
add-content $fileName  ""
add-content $fileName  "table {"
add-content $fileName  "border: thin solid #000000;"
add-content $fileName  "}"
add-content $fileName  "--&gt;"
add-content $fileName  "&lt;/style&gt;"

# HEAD end
Add-Content $fileName "&lt;/head&gt;"

# HEAD start
Add-Content $fileName "&lt;body&gt;"

# TABLE start
Add-Content $fileName "&lt;table width='100%'&gt;"

# TABLE Header
Add-Content $fileName "&lt;tr bgcolor='#7C7C7C'&gt;"
Add-Content $fileName "&lt;td width='35%'&gt;DisplayName&lt;/td&gt;"
Add-Content $fileName "&lt;td width='10%'&gt;ItemCount&lt;/td&gt;"
Add-Content $fileName "&lt;td width='10%'&gt;TotalItemSize&lt;/td&gt;"
Add-Content $fileName "&lt;td width='25%'&gt;Database&lt;/td&gt;"
Add-Content $fileName "&lt;td width='20%'&gt;StorageLimitStatus&lt;/td&gt;"
Add-Content $fileName "&lt;/tr&gt;"

$alternateTableRowBackground = 0

# TABLE Content
while($alternateTableRowBackground -le $exdata.length)
{
if(($alternateTableRowBackground % 2) -eq 0)
{
Add-Content $fileName "&lt;tr bgcolor='#CCCCCC'&gt;"
}
else
{
Add-Content $fileName "&lt;tr bgcolor='#FCFCFC'&gt;"
}
Add-Content $fileName ("&lt;td width='30%'&gt;" + $exdata[$alternateTableRowBackground].DisplayName + "&lt;/td&gt;") 
Add-Content $fileName ("&lt;td width='10%'&gt;" + $exdata[$alternateTableRowBackground].ItemCount + "&lt;/td&gt;")
Add-Content $fileName ("&lt;td width='15%'&gt;" + $exdata[$alternateTableRowBackground].TotalItemSize + "&lt;/td&gt;")
Add-Content $fileName ("&lt;td width='25%'&gt;" + $exdata[$alternateTableRowBackground].Database + "&lt;/td&gt;")
#BelowLimit or NoChecking
if(($exdata[$alternateTableRowBackground].StorageLimitStatus -eq "BelowLimit") -or ($exdata[$alternateTableRowBackground].StorageLimitStatus -eq "NoChecking"))
{
Add-Content $fileName ("&lt;td bgcolor='#007F00' width='20%'&gt;" + $exdata[$alternateTableRowBackground].StorageLimitStatus + "&lt;/td&gt;")
}
#IssueWarning
if($exdata[$alternateTableRowBackground].StorageLimitStatus -eq "IssueWarning")
{
Add-Content $fileName ("&lt;td bgcolor='#7F7F00' width='20%'&gt;" + $exdata[$alternateTableRowBackground].StorageLimitStatus + "&lt;/td&gt;")
}
#ProhibitSend or MailboxDisabled
if(($exdata[$alternateTableRowBackground].StorageLimitStatus -eq "ProhibitSend") -or ($exdata[$alternateTableRowBackground].StorageLimitStatus -eq "MailboxDisabled"))
{
Add-Content $fileName ("&lt;td bgcolor='#7F0000' width='20%'&gt;" + $exdata[$alternateTableRowBackground].StorageLimitStatus + "&lt;/td&gt;")
}
Add-Content $fileName "&lt;/tr&gt;"

$alternateTableRowBackground = $alternateTableRowBackground + 1
}
# Summe Mailboxsize
Add-Content $fileName "&lt;tr bgcolor='#7C7C7C'&gt;"
Add-Content $fileName ("&lt;td width='30%'&gt;&lt;/td&gt;") 
$tempdata = MailboxStatistics -Server $MailServer | %{$_.ItemCount} | Measure-Object -Sum
Add-Content $fileName ("&lt;td width='10%'&gt;" + ($tempdata | Select-Object -expand Sum) + "&lt;/td&gt;")
$tempdata = MailboxStatistics -Server $MailServer | %{$_.TotalItemSize.Value.ToMB()} | Measure-Object -Sum
Add-Content $fileName ("&lt;td width='15%'&gt;" + ($tempdata | Select-Object -expand Sum) + " MB&lt;/td&gt;")
Add-Content $fileName ("&lt;td width='25%'&gt;&lt;/td&gt;")
Add-Content $fileName ("&lt;td width='20%'&gt;&lt;/td&gt;")


#TABLE end
Add-Content $fileName "&lt;/table&gt;"

# HEAD end
Add-Content $fileName "&lt;/body&gt;"

# HTML end
Add-Content $fileName "&lt;/html&gt;"

send-mailmessage $MailServer $fileName
</code></pre>

<p>The report is generated fine and the file gets generated but it will not an email out and I get the error. Not sure exactly why I am getting it. Thanks in advance! </p>