当前位置:网站首页>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.]所创,转载请带上原文链接,感谢
边栏推荐
- Istio流量管理--Ingress Gateway
- Xamarin deploys IOS from scratch Walterlv.CloudKeyboard application
- BCCOIN告诉您:年底最靠谱的投资项目是什么!
- C language I blog assignment 03
- How to deploy pytorch lightning model to production
- 仅用六种字符来完成Hello World,你能做到吗?
- Istio traffic management -- progress gateway
- 用科技赋能教育创新与重构 华为将教育信息化落到实处
- 虚拟机中安装 macOS 11 big sur
- Research on WLAN direct connection (peer-to-peer connection or P2P) and cross platform research of IOS
猜你喜欢

C language I blog assignment 03

TCP协议如何确保可靠传输

Solve Safari browser download file name garbled problem

Web novice problem of attacking and defending the world

为 Docsify 自动生成 RSS 订阅

Analysis of ArrayList source code

Harbor项目高手问答及赠书活动

YGC问题排查,又让我涨姿势了!

入门级!教你小程序开发不求人(附网盘链接)

Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
随机推荐
为什么 Schnorr 签名被誉为比特币 Segwit 后的最大技术更新
Istio traffic management -- progress gateway
11 server monitoring tools commonly used by operation and maintenance personnel
Game optimization performance (11) - Zhihu
PMP心得分享
VC + + specified directory file output by time
Function periodic table filter value selectedvalue
Q & A and book giving activities of harbor project experts
Px4 adds new applications
个人目前技术栈
阿里撕下电商标签
PMP experience sharing
Bccoin tells you: what is the most reliable investment project at the end of the year!
游戏优化性能杂谈(十一) - 知乎
[computer network] learning notes, Part 3: data link layer (Xie Xiren version)
AMD Zen3首发评测:频率超5GHz,IPC提升不止19%,这次真的Yes了 - 知乎
墨者学院SQL注入解题
laravel8更新之速率限制改进
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
笔试面试题目:求丢失的猪