当前位置:网站首页>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.]所创,转载请带上原文链接,感谢
边栏推荐
- Improvement of rate limit for laravel8 update
- Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
- 运维人员常用到的 11 款服务器监控工具
- 推荐一部经济科普视频,很有价值!
- Win10 Terminal + WSL 2 安装配置指南,精致开发体验
- laravel8更新之速率限制改进
- VC++指定目录下文件按时间排序输出
- Xamarin deploys IOS from scratch Walterlv.CloudKeyboard application
- Where is the new target market? What is the anchored product? |Ten questions 2021 Chinese enterprise service
- 蘑菇街电商交易平台服务架构及改造优化历程(含PPT)
猜你喜欢

C语言I博客作业03

Japan PSE certification

Deeplight Technology Bluetooth protocol SRRC certification services

在51CTO学院Get到PMP证书

浅谈单调栈

Oops, the system is under attack again

Adobe Lightroom / LR 2021 software installation package (with installation tutorial)

这次,快手终于比抖音'快'了!

【计算机网络】学习笔记,第三篇:数据链路层(谢希仁版)

11 server monitoring tools commonly used by operation and maintenance personnel
随机推荐
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
YGC问题排查,又让我涨姿势了!
That's what software testing is all about?!
当Kubernetes遇到机密计算,看阿里巴巴如何保护容器内数据的安全!(附网盘链接)
年轻一代 winner 的程序人生,改变世界的起点藏在身边
PCIe 枚举过程
不多不少,大学里必做的五件事(从我的大一说起)
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
Learning summary (about deep learning, vision and learning experience)
Px4 adds new applications
OR Talk NO.19 | Facebook田渊栋博士:基于蒙特卡洛树搜索的隐动作集黑盒优化 - 知乎
C语言I博客作业03
Q & A and book giving activities of harbor project experts
C language I blog assignment 03
运维人员常用到的 11 款服务器监控工具
Flink的sink实战之一:初探
PMP考试通过心得分享
Istio traffic management -- progress gateway
211 postgraduate entrance examination failed, stay up for two months, get the byte offer! [face to face sharing]
渤海银行百万级罚单不断:李伏安却称治理完善,增速呈下滑趋势