当前位置:网站首页>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.]所创,转载请带上原文链接,感谢
边栏推荐
- 2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
- 在51CTO学院Get到PMP证书
- 2 days, using 4 hours after work to develop a test tool
- Installing MacOS 11 Big Sur in virtual machine
- Iqkeyboardmanager source code to see
- Entry level! Teach you how to develop small programs without asking for help (with internet disk link)
- It's 20% faster than python. Are you excited?
- 蘑菇街电商交易平台服务架构及改造优化历程(含PPT)
- Written interview topic: looking for the lost pig
- 第二次作业
猜你喜欢
随机推荐
Is software testing training class easy to find a job
Personal current technology stack
laravel8更新之速率限制改进
AMD Zen3首发评测:频率超5GHz,IPC提升不止19%,这次真的Yes了 - 知乎
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
学习小结(关于深度学习、视觉和学习体会)
渤海银行百万级罚单不断:李伏安却称治理完善,增速呈下滑趋势
Recommend an economic science video, very valuable!
Powershell 使用.Net对象发送邮件
Second assignment
PCIe 枚举过程
PX4添加新的应用
Deeplight Technology Bluetooth protocol SRRC certification services
仅用六种字符来完成Hello World,你能做到吗?
为什么 Schnorr 签名被誉为比特币 Segwit 后的最大技术更新
Python basic syntax variables
函数周期表丨筛选丨值丨SELECTEDVALUE - 知乎
攻防世界之web新手题
Research on WLAN direct connection (peer-to-peer connection or P2P) and cross platform research of IOS
C language I blog assignment 03

