用如下脚本,可以实现,目前此脚本我在2010和2013的测试环境中测试过,都没有问题,但是在生产环境中无法实现
<?xml version="1.0" encoding="utf-8" ?>
<Configuration version="1.0">
<Feature Name="Welcome Email" Cmdlets="New-Mailbox,Enable-Mailbox">
<ApiCall Name="OnComplete">
if($succeeded) {
if ($provisioningHandler.TaskName -eq "New-Mailbox") {
$USRdname=$provisioningHandler.UserSpecifiedParameters["Name"]
$tempmsg= [string] (get-content
("c:\welcome.htm"))
$tempmsg = $tempmsg -replace "NewUser00",$USRdname
$Ualias=$provisioningHandler.UserSpecifiedParameters["Alias"]
$pSMTP = (get-mailbox $Ualias | select-object PrimarySMTPAddress | Format-Wide | Out-String ).trim()
}
elseif ($provisioningHandler.TaskName -eq "Enable-Mailbox") {
$eUalias=$provisioningHandler.UserSpecifiedParameters["Alias"]
$dName = (get-mailbox $eUalias | select-object Name | Format-Wide | Out-String ).trim()
$pSMTP = (get-mailbox $eUalias | select-object PrimarySMTPAddress | Format-Wide | Out-String ).trim()
$tempmsg= [string] (get-content ("c:\welcome.htm"))
$tempmsg = $tempmsg -replace "NewUser00",$dName
}
$HUBServer="10.83.40.35"
$EMail =new-object net.mail.mailmessage
$HUBTask = new-object net.mail.smtpclient($HUBServer)
$EMail.From="momohr@immomo.com"
$EMail.To.add($pSMTP)
$EMail.Subject="欢迎加入xx!"
$EMail.Body= $tempmsg
$Email.IsBodyHtml = $true
$HUBTask.send($EMail)
}
</ApiCall>
</Feature>
</Configuration>
在生产环境中进行配置,启用户时,都会有如下警告
具备索引5 的cmdlet
扩展代理在OnComplete() 中引发了异常。异常情况为: Microsoft.Exchange.Provisioning.ProvisioningException: ScriptingAgent:
对OnComplete API 调用Scriptlet
时引发了异常: 使用“1”个参数调用“Send”时发生异常:“事务失败。
服务器响应为:5.6.0 Invalid message content”。---> System.Management.Automation.MethodInvocationException:
使用“1”个参数调用“Send”时发生异常:“事务失败。
服务器响应为:5.6.0 Invalid message content”---> System.Net.Mail.SmtpException:
事务失败。 服务器响应为:5.6.0 Invalid message content
在System.Net.Mail.DataStopCommand.CheckResponse(SmtpStatusCode statusCode, String serverResponse)
在System.Net.Mail.DataStopCommand.Send(SmtpConnection conn)
在System.Net.Mail.SmtpClient.Send(MailMessage message)
在 CallSite.Target(Closure , CallSite , Object , Object ) ---
内部异常堆栈跟踪的结尾--- 在System.Management.Automation.ExceptionHandlingOps.ConvertToMethodInvocationException(Exception exception, Type typeToThrow, String methodName, Int32 numArgs, MemberInfo
memberInfo) 在CallSite.Target(Closure , CallSite , Object , Object )
在System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
在System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
在System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) ---
内部异常堆栈跟踪的结尾--- 在Microsoft.Exchange.ProvisioningAgent.ScriptingAgentHandler.OnComplete(Boolean succeeded, Exception e)
在Microsoft.Exchange.Provisioning.ProvisioningLayer.OnCompleteImpl(Task task, Boolean succeeded, Exception exception)
用户没有收到欢迎邮件。
如上会是什么原因导致的呢?