当前位置:网站首页>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.]所创,转载请带上原文链接,感谢
边栏推荐
- Japan PSE certification
- Deeplight Technology Bluetooth protocol SRRC certification services
- 2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
- 值得一看!EMR弹性低成本离线大数据分析最佳实践(附网盘链接)
- 413【毕设课设】基于51单片机无线zigbee无线智能家居光照温湿度传输监测系统
- 当Kubernetes遇到机密计算,看阿里巴巴如何保护容器内数据的安全!(附网盘链接)
- Rust : 性能测试criterion库
- How to deploy pytorch lightning model to production
- 笔试面试题目:盛水最多的容器
- 漫画|讲解一下如何写简历&项目
猜你喜欢

Personal current technology stack

2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...

Q & A and book giving activities of harbor project experts

软件测试培训班出来好找工作么

笔试面试题目:判断单链表是否有环

413【毕设课设】基于51单片机无线zigbee无线智能家居光照温湿度传输监测系统

Analysis of istio access control

渤海银行百万级罚单不断:李伏安却称治理完善,增速呈下滑趋势

不多不少,大学里必做的五件事(从我的大一说起)

Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
随机推荐
Improvement of rate limit for laravel8 update
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
Service architecture and transformation optimization process of e-commerce trading platform in mogujie (including ppt)
狗狗也能操作无人机!你没看错,不过这其实是架自动驾驶无人机 - 知乎
PMP考试通过心得分享
【计算机网络】学习笔记,第三篇:数据链路层(谢希仁版)
漫画|讲解一下如何写简历&项目
413【毕设课设】基于51单片机无线zigbee无线智能家居光照温湿度传输监测系统
Second assignment
渤海银行百万级罚单不断:李伏安却称治理完善,增速呈下滑趋势
Adobe media encoder /Me 2021软件安装包(附安装教程)
Flink的sink实战之一:初探
软件测试就是这么回事?!
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
YGC问题排查,又让我涨姿势了!
Win10 Terminal + WSL 2 安装配置指南,精致开发体验
Ali! Visual computing developer's series of manuals (with internet disk link)
我们采访了阿里云云数据库SQL Server的产品经理,他说了解这四个问题就可以了...
个人目前技术栈
阿里撕下电商标签