使用PowerShell发送带附件的Email
来源:互联网 发布:男士背包推荐 知乎 编辑:程序博客网 时间:2024/06/10 17:24
该脚本使用Exchange插件发送mail。
打开Powershell ISE,复制下面的脚本并添加正确的email地址即可。
ClearAdd-PSSnapin Microsoft.Exchange.Management.Powershell.Admin -erroraction silentlyContinuefunction sendmail_withAttachment {Param (#[Parameter(Mandatory=$true)][string] $smtpServer = "192.21.168.121",[string] $From_mail = "Sxxxx@abcd.com",[string] $to_mail = "Burgess.Liu@abcd.com",[string] $cc_mail = "Burgess.Liu@abcd.com",[string] $Subject = "Notification from email server")Write-Host “`n Starting script, Sending Email to Recipients.....” -ForegroundColor Green$text= ''$body = ''$text = "Attached is the email server mailbox report"$body = "<font color=red><b>$text</b></font><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>"$body += "--------------------------------------------------------------------------------------------------------" $body += "<footer><p><font size=2>Contact DBA Team if you have any question.<Br>--------------------------------------------------------------------------------------------------------</footer></font><br>" $filename = "tmuninst.ini"$file= "C:\" + $filename$att = new-object Net.Mail.Attachment($file)$msg = new-object Net.Mail.MailMessage$smtp = new-object Net.Mail.SmtpClient($smtpServer)#$smtp.Send($smtpFrom,$smtpTo,$messagesubject,$messagebody) $msg.IsBodyHTML = $true$msg.Body = $body $msg.From = $From_mail;$msg.To.Add($to_mail)$msg.CC.Add($cc_mail)$msg.Subject = $Subject;$logs = Get-Content $file | Out-String$msg.Attachments.Add($att)$smtp.Send($msg)#--Priority high $att.Dispose()}sendmail_withAttachment测试效果如下:
0 0
- 使用PowerShell发送带附件的Email
- python 使用smtplib发送带附件的email
- 用JavaMail发送带附件的Email
- java发送Email,带附件
- 发送email(带附件)
- Java发送email 带附件
- python发送Email 带附件
- 【原创】用php发送带附件的email
- 在 App 里发送带附件 Email 的实现代码
- Android 调用系统Email发送带多附件的邮件
- java发送email带附件完整的web工程
- 【java】实现发送带附件email
- 发送email(不带附件)
- ubuntu命令行直接发送email,带附件
- VB2013 发送邮件(Email)并带附件
- 使用javamail发送带附件的邮件
- 使用javamail发送带附件的邮件
- 使用spring 发送带附件的邮件
- 图论 DFS HDU 1010
- 每个程序员都应该收藏的算法复杂度速查表
- NYOJ 6 喷水装置(一)
- esay UI实现无限级tree
- URAL 1114 Boxes
- 使用PowerShell发送带附件的Email
- iOS 设备的唯一标识符最新
- memcached
- Java泛型-类型擦除
- ACM算法竞赛:抄课文
- Could not connect to SMTP host: smtp.qq.com, port: 25;
- Linux性能分析的前60000毫秒
- RxJava学习第一篇:RxJava和RxAndroid的关系
- UVA 10562-Undraw the Trees