当前位置:网站首页>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.]所创,转载请带上原文链接,感谢
边栏推荐
- Research on WLAN direct connection (peer-to-peer connection or P2P) and cross platform research of IOS
- 11 server monitoring tools commonly used by operation and maintenance personnel
- Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
- Analysis of ArrayList source code
- Adobe Lightroom / LR 2021 software installation package (with installation tutorial)
- 攻防世界之web新手题
- 比Python快20%,就问你兴不兴奋?
- Or talk No.19 | Facebook Dr. Tian Yuandong: black box optimization of hidden action set based on Monte Carlo tree search
- 还不快看!对于阿里云云原生数据湖体系全解读!(附网盘链接)
- Function periodic table filter value selectedvalue
猜你喜欢
渤海银行百万级罚单不断:李伏安却称治理完善,增速呈下滑趋势
The young generation of winner's programming life, the starting point of changing the world is hidden around
C语言I博客作业03
还不快看!对于阿里云云原生数据湖体系全解读!(附网盘链接)
Win10 Terminal + WSL 2 安装配置指南,精致开发体验
Rust : 性能测试criterion库
Or talk No.19 | Facebook Dr. Tian Yuandong: black box optimization of hidden action set based on Monte Carlo tree search
PMP experience sharing
Solve Safari browser download file name garbled problem
C语言I博客作业03
随机推荐
[data structure Python description] use hash table to manually implement a dictionary class based on Python interpreter
OR Talk NO.19 | Facebook田渊栋博士:基于蒙特卡洛树搜索的隐动作集黑盒优化 - 知乎
Adobe media encoder /Me 2021软件安装包(附安装教程)
Rust : 性能测试criterion库
供货紧张!苹果被曝 iPhone 12 电源芯片产能不足
Service architecture and transformation optimization process of e-commerce trading platform in mogujie (including ppt)
The young generation of winner's programming life, the starting point of changing the world is hidden around
一个方案提升Flutter内存利用率
华为云重大变革:Cloud&AI 升至华为第四大 BG ,火力全开
Web novice problem of attacking and defending the world
Dogs can also operate drones! You're right, but it's actually an autonomous drone - you know
漫画|讲解一下如何写简历&项目
Istio traffic management -- progress gateway
YGC问题排查,又让我涨姿势了!
Research on WLAN direct connection (peer-to-peer connection or P2P) and cross platform research of IOS
Where is the new target market? What is the anchored product? |Ten questions 2021 Chinese enterprise service
Tidb performance competition 11.02-11.06
软件测试就是这么回事?!
Personal current technology stack
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...