当前位置:网站首页>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.]所创,转载请带上原文链接,感谢
边栏推荐
- Ali! Visual computing developer's series of manuals (with internet disk link)
- OR Talk NO.19 | Facebook田渊栋博士:基于蒙特卡洛树搜索的隐动作集黑盒优化 - 知乎
- 年轻一代 winner 的程序人生,改变世界的起点藏在身边
- VC + + specified directory file output by time
- [computer network] learning notes, Part 3: data link layer (Xie Xiren version)
- From a friend recently Ali, Tencent, meituan and other P7 Python development post interview questions
- Get PMP certificate at 51CTO College
- Bccoin tells you: what is the most reliable investment project at the end of the year!
- Win10 terminal + WSL 2 installation and configuration guide, exquisite development experience
- Adobe Lightroom /Lr 2021软件安装包(附安装教程)
猜你喜欢

That's what software testing is all about?!

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

Written interview questions: find the smallest positive integer missing

函数周期表丨筛选丨值丨SELECTEDVALUE - 知乎

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

C语言I博客作业03

PMP心得分享

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

ArrayList源码分析

新的目标市场在哪里?锚定的产品是什么?| 十问2021中国企业服务
随机推荐
吐血整理!阿里巴巴 Android 开发手册!(附网盘链接)
Istio traffic management -- progress gateway
211考研失败后,熬夜了两个月拿下字节offer!【面经分享】
Introduction to mongodb foundation of distributed document storage database
狗狗也能操作无人机!你没看错,不过这其实是架自动驾驶无人机 - 知乎
阿里教你深入浅出玩转物联网平台!(附网盘链接)
VC++指定目录下文件按时间排序输出
攻防世界之web新手题
“1024”征文活动结果新鲜出炉!快来看看是否榜上有名?~~
笔试面试题目:盛水最多的容器
Japan PSE certification
AMD Zen3首发评测:频率超5GHz,IPC提升不止19%,这次真的Yes了 - 知乎
笔试面试题目:求丢失的猪
Flink的sink实战之一:初探
How TCP protocol ensures reliable transmission
Or talk No.19 | Facebook Dr. Tian Yuandong: black box optimization of hidden action set based on Monte Carlo tree search
BCCOIN告诉您:年底最靠谱的投资项目是什么!
软件测试培训班出来好找工作么
为什么 Schnorr 签名被誉为比特币 Segwit 后的最大技术更新
Win10 Terminal + WSL 2 安装配置指南,精致开发体验