Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Powershell email with body as html

336 views
Skip to first unread message

Tony Hughes

unread,
Feb 6, 2010, 2:21:09 AM2/6/10
to
Hi All,

First time posting hopefully you guys can help

I am using the below script to try and attach a htm/html as the body
of an email. The HTML is an export of a free disk report unfortunately
no matter what i do with the attachment section the only this that
shows up is the path i.e. "D:\apps\1.htm" show's up i've tried |
convert-tohtml etc just get things like *16 or *24 in the body of the
email.

$logFilePath = "C:\Documents and Settings\xzw6qc
\AAUNSWC48_20100206.htm"
$body = "C:\Documents and Settings\xzw6qc\AAUNSWC48_20100206.htm"

#Email function
function sendmail($attachment)
{
$SmtpClient = New-Object system.net.mail.smtpClient
$MailMessage = New-Object system.net.mail.mailmessage
$Attachment = New-Object System.Net.Mail.Attachment($logfilepath)
$SmtpClient.Host = “mailrelay.XXXX”
$mailmessage.from = “test@XXXX"
$mailmessage.To.add(“anthony.hughes@XXXX”)
$mailmessage.Subject = “Storage Group Copy Status report”
$MailMessage.IsBodyHtml = 1
$mailmessage.Body = $body
$MailMessage.Attachments.Add($Attachment)
$smtpclient.Send($mailmessage)
}

sendmail $AllServers


All i get is the attachment and

C:\Documents and Settings\xzw6qc\AAUNSWC48_20100206.htm in the body
want is as viewable in the email without it being an attachment :-)


Any help would be muchly appreciated...

Tony Hughes

unread,
Feb 6, 2010, 7:26:53 AM2/6/10
to
Ended up being get-content

OK

unread,
Feb 6, 2010, 3:47:01 PM2/6/10
to
$attachments is path collection:

if( $attachments -ne "" ) {
foreach($private:attachment in $attachments) {
if(Test-Path $attachment) {
[System.Net.Mail.Attachment] $private:data = new-object
System.Net.Mail.Attachment( $attachment );
$message.Attachments.Add( $data );
}
}
}

Martin Zugec

unread,
Feb 8, 2010, 6:59:54 AM2/8/10
to

...and don't forget to dispose mail object, because it will lock all
attached files!

Martin

"OK" <O...@discussions.microsoft.com> wrote in message
news:BD308593-1EDC-4F3F...@microsoft.com...

OK

unread,
Feb 8, 2010, 11:45:01 AM2/8/10
to
Martin,
> ....and don't forget to dispose mail object, because it will lock all
> attached files!
Good call.
I don't do it becase it's last step before script exits and PS too.
I have sheduled job to run PS to run the script.

Martin Zugec

unread,
Feb 9, 2010, 3:06:36 AM2/9/10
to
Well, that's what I did in the past... Than I added few more lines to do
something with attached file and bang :)

Martin

"OK" <O...@discussions.microsoft.com> wrote in message

news:7C24033B-5C62-48F3...@microsoft.com...

0 new messages