Thursday, October 20, 2011

Sending mail with image in PowerShell

$smtpServer = "<smtp server name>"
$msg = new-object Net.Mail.MailMessage
$att = new-object Net.Mail.Attachment("<image path>")
$att.ContentDisposition.Inline = $True
$att.ContentDisposition.DispositionType = "Inline"
$att.ContentType.MediaType = "image/jpeg"
$att.ContentId = "logo"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.IsBodyHTML = $True
$msg.From = "<from address>"
$msg.To.Add("<to address>")
$"<cc address>")
$msg.Subject = "<mail subject>"
$msg.Body = "<mail body>... <img src='cid:logo'>"
Add-Content -Path "d:\mylog.txt" -Value "Mail Sent..."

No comments:

Post a Comment

How to launch a document by clicking a link to the file?

Word: <a href='ms-word:ofe|u|path/to/web/word/document.docx'>Link to document</a> Excel: <a href='ms-excel:o...