Ovde ti je primer powershell skripta koji priprema html mail za slanje.
Ključno za slanje slike unutar maila, a ne kao attachment je:
$attachment = New-Object System.Net.Mail.Attachment –ArgumentList "C:\temp\NEKI.jpg"
$attachment.ContentDisposition.Inline = $True
$attachment.ContentDisposition.DispositionType = "Inline"
$attachment.ContentType.MediaType = "image/jpg"
$attachment.ContentId = 'NEKI.jpg'
Dakle, mora se navesti da je attachment INLINE, kako bi se pojavio u tekstu, a ne tamo gde se bi ga stavio ako nije inline.
Code:
$smtpServer = "xxx.xxx.xxx.xxx"
$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$Smtp.Credentials = New-Object System.Net.NetworkCredential("USERNAME","PASSWORD","DOMAIN")
$msg.From = "MAIL ADRESA POŠILAJOCA"
$msg.subject = "SUBJECT MAILA"
$msg.IsBodyHtml = $True
$msg.body = [IO.File]::ReadAllText("c:\temp\NEKI.html")
$attachment = New-Object System.Net.Mail.Attachment –ArgumentList "C:\temp\NEKI.jpg"
$attachment.ContentDisposition.Inline = $True
$attachment.ContentDisposition.DispositionType = "Inline"
$attachment.ContentType.MediaType = "image/jpg"
$attachment.ContentId = 'NEKI.jpg'
$msg.Attachments.Add($attachment)
Ovde je deo iz html teksta maila, gde se vidi kako se referenciraš na inline sliku u telu maila:
Code (html):<img src="cid:NEKI.jpg" height="345" width="550" alt="NEKI ALT">