为什么发送电子邮件插件不工作?
我创建了一个插件(使用开发人员工具包),该插件将发送邮件到Participants
,该邮件在创建Participants
时转换为Contacts
。 但是这个插件不工作。当我试图调试它时,下面的消息出现在插件注册工具(SDK)中为什么发送电子邮件插件不工作?
Profiler> Plug-in AppDomain Created
Profiler> Parsed Profiler File Successfully.
Profiler> Constructor Execution Started: XXXXXXXX
Profiler> Constructor Execution Completed Successfully (Duration = 8ms).
Profiler> Profiler Execution Started: XXXXXXXXXXX
Plug-in> Entered CRMEmailToParticipantsPackage.EmailPlugins.PostParticipantCreate.Execute(),
Plug-in> Exiting CRMEmailToParticipantsPackage.EmailPlugins.PostParticipantCreate.Execute(),
Profiler> Profiler Execution Completed Successfully (Duration = 57ms).
Profiler> Profiler AppDomain Unloaded
。管道阶段是对创建消息进行预验证。 这是我的代码:
protected void ExecutePostParticipantCreate(LocalPluginContext localContext)
{
if (localContext == null)
{
throw new ArgumentNullException("localContext");
}
// TODO: Implement your custom Plug-in business logic.
IPluginExecutionContext context = localContext.PluginExecutionContext;
IOrganizationService service = localContext.OrganizationService;
if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"] is Entity)
{
try
{
Entity entity = (Entity)context.InputParameters["Target"];
if (entity.LogicalName == "new_participant")
{
Guid Contact_id = ((EntityReference)entity.Attributes["new_participantscontact"]).Id;
Guid trip_Id = ((EntityReference)entity.Attributes["new_tripparticipants"]).Id;
ColumnSet col1 = new ColumnSet("new_name", "new_date", "new_destination");
Entity trip = service.Retrieve("new_trip", trip_Id, col1);
var Trip_name = trip.Attributes["new_name"];
var Trip_date = trip.Attributes["new_date"];
var Trip_destination = trip.Attributes["new_destination"];
string emailBody = "Hi, your " + Trip_name.ToString() + "is booked on : " + Trip_date.ToString() + "; Destination : " + Trip_destination.ToString();
Guid _userId = context.UserId;
ActivityParty fromParty = new ActivityParty
{
PartyId = new EntityReference(SystemUser.EntityLogicalName, _userId)
};
ActivityParty toParty = new ActivityParty
{
PartyId = new EntityReference("new_participantscontact", Contact_id)
};
Email email = new Email
{
To = new ActivityParty[] { toParty },
From = new ActivityParty[] { fromParty },
Subject =Trip_name.ToString()+ " :Trip Details",
Description = emailBody,
DirectionCode = true
};
Guid emailID = service.Create(email);
SendEmailRequest req = new SendEmailRequest();
req.EmailId = emailID;
req.TrackingToken = "";
req.IssueSend = true;
SendEmailResponse res = (SendEmailResponse)service.Execute(req);
}
}
catch (FaultException ex)
{
throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
}
}
}
我有没有做过任何事情错在这里?
谢谢。
我认为第一件事就是发现你的插件是否被解雇。尝试debug或使用ITracingService来知道。如果你发现你的插件没有被解雇,代码是不必要的。请注意,在CRM Online中部署插件只能在沙盒模式下运行。尝试在CRM Online中看到这个step-by-step插件的部署。
嗨佩德罗,我编辑了这个问题。 – 2013-03-14 09:51:49
您能否使用此处列出的步骤进行调试:http://microsoftcrmworld.blogspot.com/2013/01/debug-plugins-on-your-local-pc-without.html?
如果没有,您可以添加一些localContext.trace()调用,然后在执行方法的最后引发异常。下载并查看日志文件以查看localContext.trace()的输出。这会让你知道发生了什么。
我的代码发送邮件是否正确? – 2013-03-15 05:49:58
看起来不错,电子邮件实体是否已创建但未发送? – 2013-03-15 16:03:54
是的。无论如何知道背后的原因? – 2013-03-16 05:35:43
您的代码似乎很好... 我观察到您正在向自定义实体发送邮件... 您是否在定制过程中启用了“发送电子邮件”选项?
是的,我已启用该功能。 – 2013-03-16 05:32:29
你怎么知道插件没有烧制? – 2013-03-14 09:28:00
Sry它的解雇,我正在使用SDK pluginregistration工具分析这个插件,同时调试什么都没有发生 – 2013-03-14 09:40:44