2

We are adding Contact and sending email in Sitecore 9.1.1. We dont want to show that contact in Experience profile so we are deleting that contact on same method after sending email. However, log file showing the below error :

WARN  Unhandled exception thrown while processing task '0xB18D3ABA71473240B0D4C6B889600324' from task pool 'dispatch_failed_task_pool'. The task has not reached the maximum number of attempts to process a failing task and is postponed.
Exception: System.ArgumentNullException
Message: Value cannot be null.
Parameter name: contact
Source: Sitecore.Kernel
   at Sitecore.Diagnostics.Assert.ArgumentNotNull(Object argument, String argumentName)
   at Sitecore.EmailCampaign.Cm.Pipelines.UpdateUndeliveredCount.UpdateBounceCount(HandleMessageEventPipelineArgs args, Contact contact)
   at (Object , Object )
   at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
   at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain, Boolean failIfNotExists)
   at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain)
   at Sitecore.Modules.EmailCampaign.Core.PipelineHelper.RunPipeline(String pipelineName, PipelineArgs args)
   at Sitecore.EmailCampaign.Cm.Tasks.MessageEventBaseTaskProcessor.OnProcess(ShortRunningTask task, CancellationToken cancellationToken)
   at Sitecore.ExM.Framework.Distributed.Tasks.Processing.ShortRunning.TaskProcessor.Process(ShortRunningTask task, CancellationToken cancellationToken)
   at Sitecore.ExM.Framework.Distributed.Tasks.Processing.ShortRunning.DatabaseTaskAgent.ProcessTask(DatabaseTaskDtoCollectionItem taskDto, CancellationToken cancellationToken)

When we are adding breakpoint in the code there and wait for few second then we are getting email and contact removed code working fine. Only issue here we need to send email as well before deleting that contact.

We are using the below code for sending the email :

var message = new AutomatedMessage();
            message.ContactIdentifier =contact;
            message.MessageId = messageId;
            message.TargetLanguage = Sitecore.Context.Language.Name;
            clientApiService.SendAutomatedMessage(message);

For deleting contact details we are using the below code :

var reference = new Sitecore.XConnect.IdentifiedContactReference(source, identifier);
Contact contact = client.Get<Sitecore.XConnect.Contact>(reference, new Sitecore.XConnect.ContactExpandOptions() { });
client.ExecuteRightToBeForgotten(contact);
client.Submit();

Could someone suggest me how can we achieve this functionality?

1
  • You need to include all of the code involved, including the contact deletion code. So the full flow can be examined. Also, fix the question title.
    – Mark Cassidy
    Commented May 13, 2021 at 8:14

1 Answer 1

4

Email Experience Manager(ExM) doesn't send and finish all things related to email immediately.

Your code will put the email into an "automated message bus". And then your email will be sent. After sending of email, other tasks will be executed, e.g. update reporting database with data about the new email. It happens quickly, but not immediately. That is why you could not execute removing a contact right after calling Send method. Because contact is still required to properly finish all tasks.

You have a few options how to overcome it:

  1. Try to use the "Exclude From Reports" and "Service Message" checkboxes on your email. (Hopefully, it will work, if not you will need to chose between 2nd and 3rd) enter image description here
  2. Use marketing automation tool. Add Contact to the campaign which consists of 2 actions: sending an email and remove contact with a delay between them.
  3. Do not use ExM for this task. If you removing contact right after sending an email, it sounds like you don't really need all ExM features. And that is why you probably may not need to use ExM for sending an email. You can use built-in .Net SmtpClient to send emails.
5
  • About 1 option , could you please let me know where these are the options? I would like to try first option.
    – Ashu
    Commented Jun 4, 2021 at 10:28
  • @AjaySharma Checkboxes on your email item in the System section.
    – Anton
    Commented Jun 4, 2021 at 11:33
  • @Anton, option 1 is working fine on standalone role. However, it is not working on CD role.
    – User7864
    Commented Jun 7, 2021 at 14:19
  • @Anton, thank you but this is not working on CD server. Is there any setting for CD role ?
    – Ashu
    Commented Jun 8, 2021 at 3:05
  • @AjaySharma no, there is no separate setting for CD.
    – Anton
    Commented Jun 8, 2021 at 8:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.