当前位置:网站首页>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.]所创,转载请带上原文链接,感谢
边栏推荐
- 2天,利用下班后的4小时开发一个测试工具
- Where is the new target market? What is the anchored product? |Ten questions 2021 Chinese enterprise service
- Installing MacOS 11 Big Sur in virtual machine
- Or talk No.19 | Facebook Dr. Tian Yuandong: black box optimization of hidden action set based on Monte Carlo tree search
- OR Talk NO.19 | Facebook田渊栋博士:基于蒙特卡洛树搜索的隐动作集黑盒优化 - 知乎
- Q & A and book giving activities of harbor project experts
- On monotonous stack
- Automatically generate RSS feeds for docsify
- What can your cloud server do? What is the purpose of cloud server?
- From a friend recently Ali, Tencent, meituan and other P7 Python development post interview questions
猜你喜欢
2020-11-05
11 server monitoring tools commonly used by operation and maintenance personnel
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
Where is the new target market? What is the anchored product? |Ten questions 2021 Chinese enterprise service
狗狗也能操作无人机!你没看错,不过这其实是架自动驾驶无人机 - 知乎
211 postgraduate entrance examination failed, stay up for two months, get the byte offer! [face to face sharing]
Xamarin 从零开始部署 iOS 上的 Walterlv.CloudKeyboard 应用
你的云服务器可以用来做什么?云服务器有什么用途?
Get PMP certificate at 51CTO College
Hematemesis! Alibaba Android Development Manual! (Internet disk link attached)
随机推荐
PX4添加新的应用
C language I blog assignment 03
2020-11-05
python小工具:编码转换
2 days, using 4 hours after work to develop a test tool
你的云服务器可以用来做什么?云服务器有什么用途?
Win10 terminal + WSL 2 installation and configuration guide, exquisite development experience
渤海银行百万级罚单不断:李伏安却称治理完善,增速呈下滑趋势
Deeplight Technology Bluetooth protocol SRRC certification services
游戏优化性能杂谈(十一) - 知乎
Game optimization performance (11) - Zhihu
2020-11-05
C语言I博客作业03
笔试面试题目:求缺失的最小正整数
比Python快20%,就问你兴不兴奋?
IQKeyboardManager 源代码看看
来自朋友最近阿里、腾讯、美团等P7级Python开发岗位面试题
你搞不懂与别人的差距,永远成不了架构师!月薪15K和月薪65K,你差在那了?
[data structure Python description] use hash table to manually implement a dictionary class based on Python interpreter
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom