当前位置:网站首页>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.]所创,转载请带上原文链接,感谢
边栏推荐
- Xamarin 从零开始部署 iOS 上的 Walterlv.CloudKeyboard 应用
- Flink's sink: a preliminary study
- 比Python快20%,就问你兴不兴奋?
- 分布式文档存储数据库之MongoDB基础入门
- YGC问题排查,又让我涨姿势了!
- 浅谈单调栈
- C language I blog assignment 03
- Game optimization performance (11) - Zhihu
- Service architecture and transformation optimization process of e-commerce trading platform in mogujie (including ppt)
- Second assignment
猜你喜欢
还不快看!对于阿里云云原生数据湖体系全解读!(附网盘链接)
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
Mozi college SQL injection solution
Python basic syntax variables
Deeplight Technology Bluetooth protocol SRRC certification services
游戏优化性能杂谈(十一) - 知乎
[data structure Python description] use hash table to manually implement a dictionary class based on Python interpreter
漫画|讲解一下如何写简历&项目
为什么 Schnorr 签名被誉为比特币 Segwit 后的最大技术更新
AMD Zen3首发评测:频率超5GHz,IPC提升不止19%,这次真的Yes了 - 知乎
随机推荐
Web novice problem of attacking and defending the world
Bohai bank million level fines continue: Li Volta said that the governance is perfect, the growth rate is declining
糟糕,系统又被攻击了
How to deploy pytorch lightning model to production
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
[data structure Python description] use hash table to manually implement a dictionary class based on Python interpreter
PDMS cutting software
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
PMP心得分享
临近双11,恶补了两个月成功拿下大厂offer,跳槽到阿里巴巴
你的云服务器可以用来做什么?云服务器有什么用途?
仅用六种字符来完成Hello World,你能做到吗?
Px4 adds new applications
阿里撕下电商标签
If you don't understand the gap with others, you will never become an architect! What's the difference between a monthly salary of 15K and a monthly salary of 65K?
Q & A and book giving activities of harbor project experts
Function periodic table filter value selectedvalue
吐血整理!阿里巴巴 Android 开发手册!(附网盘链接)
C语言I博客作业03
Flink的sink实战之一:初探