Power shell Send mail by exchanges server
来源:互联网 发布:java.util.map 编辑:程序博客网 时间:2024/05/16 18:55
<# This file is used for Send mail via exchange service owner: farawayplace613, tomcat.cheng@gmail.com date: 2012/08/23#> # Load the Microsoft.Exchange.WebServices.dll which used for commicating with exchange server$currentPath = (get-location).Path$dllPath = '{0}\Microsoft.Exchange.WebServices.dll' -f $currentPath[Reflection.Assembly]::LoadFile($dllPath)# 3 standard for ExchangeVersion.Exchange2010_SP2$exchangeService = new-object Microsoft.Exchange.WebServices.Data.ExchangeService(3)# Create the credentails which used for connecting to the exchange server$exchangeService.Credentials = new-object Microsoft.Exchange.WebServices.Data.WebCredentials("YourUserName", "YourPassword", "YourDomainName")# configure the url of the exchange services $exchangeService.Url = new-object System.Uri("https://YourExchangeServerName/EWS/Exchange.asmx")# Crate a mail $message = new-object Microsoft.Exchange.WebServices.Data.EmailMessage($exchangeService)$exchangeService.AutodiscoverUrl("xxxx@xxxx.com")$message.Subject = "Hello word from power shell via exchange service"$message.Body = "Sent using the EWS Managed API"$message.ToRecipients.Add("xxxx1@xxxxx.com")# send out the mail$message.Send()
1. You can get the Microsoft.Exchange.WebServices.dll from http://download.microsoft.com/download/1/9/0/190EDCB6-00D2-41E1-ACFA-399E045B785A/EwsManagedApi.msi, copy the Microsoft.Exchange.WebServices.dll to the same floder of your power shell file.
2. You need to install the .Net framework 4.5 from http://www.microsoft.com/zh-cn/download/details.aspx?id=30653
3. You need to allow powershell use the latest .net framwork
PowerShell (the engine) runs fine under .NET 4.0. PowerShell ( the console host and the ISE) do not, simply because they were compiled against older versions of .NET. There's a registry setting that willchange the .NET framework loaded systemwide, which will in turn allow PowerShell to use .NET 4.0 classes:
reg add hklm\software\microsoft\.netframework /v OnlyUseLatestCLR /t REG_DWORD /d 1 reg add hklm\software\wow6432node\microsoft\.netframework /v OnlyUseLatestCLR /t REG_DWORD /d 1
To update just the ISE to use .NET 4.0, you can change the config ($psHome\powershell_ise.exe.config) file to have a chunk like this:
<?xml version="1.0" encoding="utf-8"?> <configuration> <startup> <supportedRuntime version="v4.0.30319" /> </startup> </configuration>
You can build .NET 4.0 applications that call PowerShell using the PowerShell API (System.Management.Automation.PowerShell) just fine, but these steps will help get the in-the-box PowerShell hosts to work under .NET 4.0
Note:
Don't use this solution on the same server which installed SharePoint 2010, becuase it will cause sharePoint stop work since Moss 2010 doesn't support the .Net framework 4.0
- Power shell Send mail by exchanges server
- send mail by SMTP server (Python)
- Send Mail By CDO
- Sql Server Job VBScript Send Mail
- IBM supervessel power云平台 之 send mail 篇
- send Mail
- Send mail
- Send mail
- SEND MAIL
- send mail
- send mail
- send mail
- SEND MAIL
- How to send mail by EMS - 如何实现邮件特快专递
- the email title about automatic to send invoice by mail
- Send an e-mail by ABAP in OO way
- Send-only Mail Server with Exim on Ubuntu 11.04
- How Do I Send Mail From Windows 2008 Server/IIS7?
- Ext.Net 1.x_Ext.Net.GridPanel序号宽度自适应(待完善)
- Struts2.1整合dwr2的问题及解决办法
- Disable auto select after clicking magnifier
- mysql命令行下的数据导入与导出
- xcode4.2的本地化多语言支持
- Power shell Send mail by exchanges server
- js验证用户名是否可用
- SQL语句中,WHERE子句不能有聚合函数问题
- 什么是C++ traits
- 类 NSFetchedResultsController详解
- 在struts2,hibernate.spring版本包里找配置的范例文件
- IKE 2
- [内存管理] linux kernel内存映射实例分析
- 字串查找算法总结及MS的strstr源码