I was working on a project to send a html attachment in a powershell script. I have the HTML string so all I want to do is create an attachment from the string. Here's the code:
$SMTPserver = "mail.company.com"
$from = "firstname.lastname@example.org"
$to = "email@example.com"
$subject = "Test PS Attachment"
$emailbody = "test"
$attText = "The text of the attachment"
$attName = "Test.txt"
$mailer = new-object Net.Mail.SMTPclient($SMTPserver)
$msg = new-object Net.Mail.MailMessage($from, $to, $subject, $emailbody)
$att = [System.Net.Mail.Attachment]::CreateAttachmentFromString($attText,$attName)
$msg.IsBodyHTML = $false
That should get you started.
| posted on Thursday, January 19, 2012 2:39 PM