当前位置:网站首页>Shell uses. Net objects to send mail
Shell uses. Net objects to send mail
2020-11-08 11:26:00 【I'm sorry.】
There are many ways to send mail , I am used to windows powershell Self contained Send-MailMessage You can send email , This use .Net To send mail , And you need to insert local images into HTML The file of , It's important to note that the captured images name Need and HTML Medium cid:name Agreement , The reference codes are as follows :
$EmailAddress = '[email protected]'
$subject = 'Test Use Net Send Mail'
$SmtpServer = "mail.contoso.com"
$htmlbody = @'
<body>
<div>
<img src="cid:telphone.jpg" style="display:inline-block">
</div>
<span>This is test mail, use .NET send mail</span>
<div>
<img src="cid:home.png" style="display:inline-block">
</div>
</body>
'@
$MailMessage = New-Object System.Net.Mail.Mailmessage
$imagepath = 'D:\script\images'
$files = Get-ChildItem $imagepath
foreach ($file in $files)
{
$Attachment = New-Object Net.Mail.Attachment("$imagepath\$file")
$Attachment.ContentDisposition.Inline = $True
$Attachment.ContentDisposition.DispositionType = "Inline"
$Attachment.ContentType.MediaType = "image/png"
$Attachment.ContentId = $file.ToString() # file name must be equal inert into html image cid: name
$MailMessage.Attachments.Add($Attachment)
}
$MailMessage.To.Add($EmailAddress)
$MailMessage.from = '[email protected]'
$MailMessage.Subject = $subject
$MailMessage.Body = $htmlbody
$MailMessage.IsBodyHTML = $true
$MailMessage.BodyEncoding = [System.Text.Encoding]::UTF8
$MailMessage.Priority = "High"
$SmtpClient = New-Object Net.Mail.SmtpClient($SmtpServer)
$SmtpClient.UseDefaultCredentials = $false
#$SmtpClient.Credentials = New-Object System.Net.NetworkCredential("[email protected]", "123456")
$SmtpClient.Send($MailMessage)
$Attachment.dispose()
版权声明
本文为[I'm sorry.]所创,转载请带上原文链接,感谢
边栏推荐
- 阿里撕下电商标签
- Adobe media encoder /Me 2021软件安装包(附安装教程)
- 211考研失败后,熬夜了两个月拿下字节offer!【面经分享】
- Python Gadgets: code conversion
- YGC troubleshooting, let me rise again!
- Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
- Don't look! Full interpretation of Alibaba cloud's original data lake system! (Internet disk link attached)
- Rust : 性能测试criterion库
- 一个方案提升Flutter内存利用率
- Powershell 使用.Net对象发送邮件
猜你喜欢
推荐一部经济科普视频,很有价值!
Mozi college SQL injection solution
It's 20% faster than python. Are you excited?
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
Ali! Visual computing developer's series of manuals (with internet disk link)
Flink的sink实战之一:初探
C语言I博客作业03
在51CTO学院Get到PMP证书
当Kubernetes遇到机密计算,看阿里巴巴如何保护容器内数据的安全!(附网盘链接)
软件测试就是这么回事?!
随机推荐
The young generation of winner's programming life, the starting point of changing the world is hidden around
Adobe media encoder / me 2021 software installation package (with installation tutorial)
“1024”征文活动结果新鲜出炉!快来看看是否榜上有名?~~
Rust:命令行参数与环境变量操作
为什么 Schnorr 签名被誉为比特币 Segwit 后的最大技术更新
Px4 adds new applications
函数周期表丨筛选丨值丨SELECTEDVALUE - 知乎
YGC troubleshooting, let me rise again!
PCIe 枚举过程
TCP协议如何确保可靠传输
When kubernetes encounters confidential computing, see how Alibaba protects the data in the container! (Internet disk link attached)
Entry level! Teach you how to develop small programs without asking for help (with internet disk link)
Harbor项目高手问答及赠书活动
211考研失败后,熬夜了两个月拿下字节offer!【面经分享】
PCIe enumeration process
11 server monitoring tools commonly used by operation and maintenance personnel
Where is the new target market? What is the anchored product? |Ten questions 2021 Chinese enterprise service
Adobe media encoder /Me 2021软件安装包(附安装教程)
漫画|讲解一下如何写简历&项目
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom