当前位置:网站首页>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.]所创,转载请带上原文链接,感谢
边栏推荐
- A scheme to improve the memory utilization of flutter
- 2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
- Flink's sink: a preliminary study
- [computer network] learning notes, Part 3: data link layer (Xie Xiren version)
- Q & A and book giving activities of harbor project experts
- 2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
- PCIe enumeration process
- 值得一看!EMR弹性低成本离线大数据分析最佳实践(附网盘链接)
- ArrayList源码分析
- Entry level! Teach you how to develop small programs without asking for help (with internet disk link)
猜你喜欢
还不快看!对于阿里云云原生数据湖体系全解读!(附网盘链接)
在51CTO学院Get到PMP证书
211 postgraduate entrance examination failed, stay up for two months, get the byte offer! [face to face sharing]
YGC troubleshooting, let me rise again!
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
当Kubernetes遇到机密计算,看阿里巴巴如何保护容器内数据的安全!(附网盘链接)
你的云服务器可以用来做什么?云服务器有什么用途?
Powershell 使用.Net对象发送邮件
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
如何将 PyTorch Lightning 模型部署到生产中
随机推荐
入门级!教你小程序开发不求人(附网盘链接)
Xamarin deploys IOS from scratch Walterlv.CloudKeyboard application
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
Understanding design patterns
我们采访了阿里云云数据库SQL Server的产品经理,他说了解这四个问题就可以了...
Recommend an economic science video, very valuable!
Where is the new target market? What is the anchored product? |Ten questions 2021 Chinese enterprise service
还不快看!对于阿里云云原生数据湖体系全解读!(附网盘链接)
软件测试培训班出来好找工作么
供货紧张!苹果被曝 iPhone 12 电源芯片产能不足
攻防世界之web新手题
Adobe Lightroom /Lr 2021软件安装包(附安装教程)
华为云重大变革:Cloud&AI 升至华为第四大 BG ,火力全开
python基本语法 变量
笔试面试题目:判断单链表是否有环
Analysis of istio access control
你的云服务器可以用来做什么?云服务器有什么用途?
蘑菇街电商交易平台服务架构及改造优化历程(含PPT)
为什么 Schnorr 签名被誉为比特币 Segwit 后的最大技术更新
PMP experience sharing