gpt4 book ai didi

html - 使用发送邮件消息发送嵌入式图像

转载 作者:行者123 更新时间:2023-12-03 01:14:25 27 4
gpt4 key购买 nike

我正在尝试使用send-mailmessage从命令行发送带有嵌入式图像的html格式的电子邮件。我到处都看了,却找不到解决方案。我可以发送电子邮件,但是收件人没有收到图像。这是我的代码:

$smtp = "smtp.server.com" 
$to = "recp@example.com"
$from = "from@example.com"
$subject = "This is a subject"
$body = (-join(Get-content \email.html))

send-MailMessage -SmtpServer $smtp -To $to -From $from -Subject $subject -BodyAsHtml -Body $body

如果代码有问题或有其他解决方案,请通知我。谢谢!

最佳答案

您无法使用Send-MailMessage cmdlet做到这一点。要在消息中包含内嵌图像,您必须使用.NET的Net.Mail.SmtpClient类编写自己的函数。

另外,您也可以获取David Wyatt的Send-MailMessage函数,该函数已经具有所需的全部功能:

The Send-MailMessage cmdlet exposes most of the basic functionality for sending email, but you don't get a lot of control over things like attachments or alternate views. Someone on the TechNet forums was asking how to embed images into an HTML mail message, and I decided to write a version of Send-MailMessage that supports this. I started with a proxy function for the Send-MailMessage cmdlet, so all of the parameters and usage should be intact. The main difference is that I added an -InlineAttachments argument, which accepts a hashtable of pairs in the format 'ContentId'='FilePath'. You can then embed the resources into an HTML body by using URLs of the format cid:ContentId.

关于html - 使用发送邮件消息发送嵌入式图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33041698/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com