当前位置:网站首页>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.]所创,转载请带上原文链接,感谢
边栏推荐
- Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
- Solve Safari browser download file name garbled problem
- Learning summary (about deep learning, vision and learning experience)
- 运维人员常用到的 11 款服务器监控工具
- 软件测试就是这么回事?!
- Python Gadgets: code conversion
- The young generation of winner's programming life, the starting point of changing the world is hidden around
- [computer network] learning notes, Part 3: data link layer (Xie Xiren version)
- On monotonous stack
- Second assignment
猜你喜欢
值得一看!EMR弹性低成本离线大数据分析最佳实践(附网盘链接)
Second assignment
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
VC++指定目录下文件按时间排序输出
When kubernetes encounters confidential computing, see how Alibaba protects the data in the container! (Internet disk link attached)
你搞不懂与别人的差距,永远成不了架构师!月薪15K和月薪65K,你差在那了?
解析Istio访问控制
Mozi college SQL injection solution
分布式文档存储数据库之MongoDB基础入门
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
随机推荐
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
OR Talk NO.19 | Facebook田渊栋博士:基于蒙特卡洛树搜索的隐动作集黑盒优化 - 知乎
IQKeyboardManager 源代码看看
Ali teaches you how to use the Internet of things platform! (Internet disk link attached)
Recommend an economic science video, very valuable!
YGC问题排查,又让我涨姿势了!
Python Gadgets: code conversion
维图PDMS切图软件
Flink's sink: a preliminary study
最全!阿里巴巴经济体云原生实践!(附网盘链接)
Or talk No.19 | Facebook Dr. Tian Yuandong: black box optimization of hidden action set based on Monte Carlo tree search
来自朋友最近阿里、腾讯、美团等P7级Python开发岗位面试题
第二次作业
PCIe enumeration process
211 postgraduate entrance examination failed, stay up for two months, get the byte offer! [face to face sharing]
“1024”征文活动结果新鲜出炉!快来看看是否榜上有名?~~
Xamarin deploys IOS from scratch Walterlv.CloudKeyboard application
Istio traffic management -- progress gateway
你的云服务器可以用来做什么?云服务器有什么用途?
华为云重大变革:Cloud&AI 升至华为第四大 BG ,火力全开