Email Powershell发送带有图像的电子邮件
我正在尝试将一个图像嵌入到通过Powershell发送的电子邮件中 以下是我的代码:Email Powershell发送带有图像的电子邮件,email,powershell,powershell-3.0,Email,Powershell,Powershell 3.0,我正在尝试将一个图像嵌入到通过Powershell发送的电子邮件中 以下是我的代码: $Attachment=新对象Net.Mail.Attachment($LocalLocation) $Attachment.ContentDisposition.Inline=$True $Attachment.ContentDisposition.DispositionType=“Inline” $Attachment.ContentType.MediaType=“image/png” $MailMessa
$Attachment=新对象Net.Mail.Attachment($LocalLocation)
$Attachment.ContentDisposition.Inline=$True
$Attachment.ContentDisposition.DispositionType=“Inline”
$Attachment.ContentType.MediaType=“image/png”
$MailMessage=新对象Net.Mail.MailMessage
$MailMessage.To.Add($emailTo)
$MailMessage.From=$MyEmail
$MailMessage.Subject=“测试电子邮件”
$MailMessage.IsBodyHtml=$True
$MailMessage.Attachments.Add($Attachment)
$MailMessage.Body=”
"
$SmtpClient=新对象Net.Mail.SmtpClient(“123.0.0.1”,25)
$SmtpClient.Send($MailMessage)
我收到一封电子邮件,但邮件中只有一个空框。$LocalLocation是指向我的图像的链接
我正在使用Powershell 3$SendTo=“发件人邮件ID”
$SendTo = "Sender Mail ID"
$SMTPServer = "SMTP Server"
$EmailFrom = “Reciever Mail ID”
$EmailSubject = “Email including images in HTML”
$Image = "Image File"
$Message = new-object Net.Mail.MailMessage
Add-PSSnapin Microsoft.Exchange.Management.Powershell.Admin -erroraction silentlyContinue
$att = new-object Net.Mail.Attachment($Image)
$att.ContentId = "att"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$body = '<img src="cid:att" />'
$Message.From = $EmailFrom
$Message.To.Add($SendTo)
$Message.Subject = $EmailSubject
$Message.Body = $body
$Message.IsBodyHTML = $true
$Message.Attachments.Add($att)
$smtp.Send($Message)
$att.Dispose()
$SMTPServer=“SMTP服务器”
$EmailFrom=“收件人邮件ID”
$EmailSubject=“包含HTML格式图像的电子邮件”
$Image=“图像文件”
$Message=新对象Net.Mail.MailMessage
在Microsoft.Exchange.Management.Powershell.Admin中添加PSSnapin-erroraction silentlyContinue
$att=新对象Net.Mail.Attachment($Image)
$att.ContentId=“att”
$smtp=新对象Net.Mail.SmtpClient($smtpServer)
$body=''
$Message.From=$EmailFrom
$Message.To.Add($SendTo)
$Message.Subject=$EmailSubject
$Message.Body=$Body
$Message.IsBodyHTML=$true
$Message.Attachments.Add($att)
$smtp.Send($Message)
$att.Dispose()
希望此HEpls。以下是使用上述代码
Send”和“1”参数时出现的错误:“发送邮件失败”。
IMO$mailmessage.Attachments.Add($att1)
不应放在$mailmessage=New Object system.net.mail.mailmessage
之前。我希望将图像嵌入正文中。当我放入正文中时,
仍然不起作用。感谢您编写了脚本。现在您可以在引用的正文中发送消息正文中的图像$Attachment.ContentId
但我看不出你在给它赋值。