当前位置:网站首页>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.]所创,转载请带上原文链接,感谢
边栏推荐
- Is software testing training class easy to find a job
- 用科技赋能教育创新与重构 华为将教育信息化落到实处
- 2020-11-05
- When kubernetes encounters confidential computing, see how Alibaba protects the data in the container! (Internet disk link attached)
- 阿里撕下电商标签
- 如何将 PyTorch Lightning 模型部署到生产中
- 虚拟机中安装 macOS 11 big sur
- next.js实现服务端缓存
- From a friend recently Ali, Tencent, meituan and other P7 Python development post interview questions
- 墨者学院SQL注入解题
猜你喜欢
Installing MacOS 11 Big Sur in virtual machine
Solve Safari browser download file name garbled problem
PCIe enumeration process
蘑菇街电商交易平台服务架构及改造优化历程(含PPT)
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?
值得一看!EMR弹性低成本离线大数据分析最佳实践(附网盘链接)
渤海银行百万级罚单不断:李伏安却称治理完善,增速呈下滑趋势
BCCOIN告诉您:年底最靠谱的投资项目是什么!
Flink's sink: a preliminary study
为什么 Schnorr 签名被誉为比特币 Segwit 后的最大技术更新
随机推荐
吐血整理!阿里巴巴 Android 开发手册!(附网盘链接)
学习小结(关于深度学习、视觉和学习体会)
Research on WLAN direct connection (peer-to-peer connection or P2P) and cross platform research of IOS
When kubernetes encounters confidential computing, see how Alibaba protects the data in the container! (Internet disk link attached)
2天,利用下班后的4小时开发一个测试工具
Don't look! Full interpretation of Alibaba cloud's original data lake system! (Internet disk link attached)
Personal current technology stack
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
The container with the most water
YGC问题排查,又让我涨姿势了!
Flink的sink实战之一:初探
C语言I博客作业03
BCCOIN告诉您:年底最靠谱的投资项目是什么!
[computer network] learning notes, Part 3: data link layer (Xie Xiren version)
Istio traffic management -- progress gateway
Dogs can also operate drones! You're right, but it's actually an autonomous drone - you know
Deeplight Technology Bluetooth protocol SRRC certification services
TiDB 性能竞赛 11.02-11.06
Solve Safari browser download file name garbled problem
We interviewed the product manager of SQL server of Alibaba cloud database, and he said that it is enough to understand these four problems