Kentico 13 - How to add BCC to the marketing email? - kentico

I want to add BCC to the marketing email. Is there any way to do that?
I tried using the below code. But it did not work.
public override void Init()
{
EmailInfo.TYPEINFO.Events.Insert.Before += Email_Insert_Before;
}
private void Email_Insert_Before(object sender, ObjectEventArgs e)
{
var email = e.Object as EmailInfo;
email.EmailBcc = "admin#company.com";
EmailInfo.Provider.Set(email);
}

The Insert Before event is probably not the one you are looking for to customize marketing automation processes / steps. It would be easier to implement a custom Action (Marketing Automation -> Actions -> New) and tie the Action configuration to the a custom C# class. Once you have a new action, you can add Parameters to it. You could add a Parameter to let the admin configure the Email BCC.
Documentation on how to do that is here: https://docs.xperience.io/on-line-marketing-features/configuring-and-customizing-your-on-line-marketing-features/configuring-marketing-automation/developing-custom-marketing-automation-actions

Related

Bulk Edit UserRoles for Acumatica Users

I need to bulk update about 2000+ users in Acumatica (ie: Guest access users). I need to assign a new role to all of these user to support a new custom integration.
I am looking for a solution using either the Rest API or some sort of Excel bulk Import/Update that assigns the roles.
I have not had much luck working with UserRoles via the Rest API. I have only been able to download the users > user roles via a generic inquiry and ODATA. So far I have not found any documentation around this. Any guidance would be appreciated!
REST Api is not really the best tool for this job. It doesn't contain an endpoint for Users (needs to be extended) and is a bit hard to use for complex logic. There isn't an Excel import mechanism either (outside import scenarios).
I would suggest to create a Customization Plugin for this task instead.
They can be created in Acumatica customization project editor with a new CODE file:
A customization plugin is a script that is executed when you publish the customization. I tested the following code which assign Portal User role to all guest users as an example.
using System;
using PX.Data;
using Customization;
using PX.SM;
using PX.EP;
using System.Linq;
namespace UpdateUserRoles
{
public class UpdateUserRoles : CustomizationPlugin
{
public override void UpdateDatabase()
{
const string roleNameToAssign = "Portal User";
AccessUsers accessUsers = PXGraph.CreateInstance<AccessUsers>();
// For each users in the system
foreach (Users user in accessUsers.UserList.Select())
{
// Modify only guest users
if (user.Guest != true)
continue;
try
{
// Set current user
accessUsers.UserList.Current = user;
// Assign role
EPLoginTypeAllowsRole role = (EPLoginTypeAllowsRole)accessUsers.AllowedRoles.Select().RowCast<EPLoginTypeAllowsRole>()
.Where(x => x.Rolename.Contains(roleNameToAssign)).FirstOrDefault();
role.Selected = true;
accessUsers.AllowedRoles.Update(role);
WriteLog("User " + user.Username + " updated.");
}
catch (Exception ex)
{
WriteLog("Error: " + ex.Message);
}
}
accessUsers.Save.Press();
}
}
}

Sending mails to CC address in Hybris

I am trying to implement the functionality to send Order Confirmation mail to multiple recipients in CC. Anyone have idea please help.
Thanks in advance.
one solution is to extend the de.hybris.platform.acceleratorservices.email.impl.DefaultEmailGenerationService . There is a method createEmailMessage which generates and returns a EmailMessageModel in the generate method. On this MessageModel, you can set the needed properties. An example code snippet would be something like this.
public class MyEmailGenerationService extends DefaultEmailGenerationService implements EmailGenerationAndSendService {
#Override
public EmailMessageModel generate(final BusinessProcessModel businessProcessModel, final EmailPageModel emailPageModel)
throws RuntimeException {
//Make a check for your businessProcessModel if it is
if (businessProcessModel instanceof OrderProcessModel) {
EmailMessageModel myCustomMessage = super.createEmailMessage("Your Subject", "Your body", emailContext);
myCustomMessage.setCcAddresses(new ArrayList<EmailAddressModel>()); // Here add the list of the cc you want to send.
}
}
}

How to stop 'Send order notification' & 'Send payment notification' in checkout process from code side in kentico

I know there is option in kentico admin setting to stop the sending notification email. but I want to check this in the code for my customization. so could you please suggest me where should I get the code in kentico.
Setting in kentico
Please refer to the official documentation.
You need to use SettingsKeyInfoProvider:
SettingsKeyInfoProvider.SetValue("CMSSettingName", "SiteName", value);
Leave out the site name parameter if you want to set it globally.
The settings names you are looking for are CMSStoreSendOrderNotification and CMSStoreSendPaymentNotification.
You can find more settings by querying the DB:
SELECT * FROM [CMS_SettingsKey] where keyname like '%cmsstoresend%'
If you are looking to intercept an action when a notification is being sent, you can use Global events for the EmailInfo object like this:
[assembly: RegisterModule(typeof(GlobalEventsModule))]
public class GlobalEventsModule : Module
{
public GlobalEventsModule() : base (typeof(GlobalEventsModule).Name)
{
}
protected override void OnInit()
{
base.OnInit();
EmailInfo.TYPEINFO.Events.Insert.Before += Insert_Before;
}
private void Insert_Before(object sender, ObjectEventArgs e)
{
// executed before an e-mail is inserted into DB
var email = (EmailInfo)e.Object;
}
}
To cancel the execution in code you can call Cancel() method (although you might get exceptions in this case - you have to test for yourself in your scenario):
private void Insert_Before(object sender, ObjectEventArgs e)
{
var email = (EmailInfo)e.Object;
e.Cancel();
}
This will also work only if you are using Email queue (which is highly recommended anyway) and will be executed for all outgoing e-mails, not just notifications.
Using the CMS.Ecommerce library you can check these settings through the API
SiteInfoIdentifier sii = new SiteInfoIdentifier(SiteContext.CurrentSiteID);
bool sendOrderNotificationEmail = CMS.Ecommerce.ECommerceSettings.SendOrderNotification(sii);
If you wanted to set them programmatically you would have to use the SettingsKeyInfoProvider
SettingsKeyInfoProvider.SetValue("CMSStoreSendOrderNotification ", false);

workflow replicator activity: how to determine if task was approved or rejected

I have basic workflow with replicator activity inside it. Replicator contains my custom sequence activity with standard create task --> ontaskchanged --> complete task sequence.
Now: tasks are created and can be completed without problem. The thing is I cannot find a way to get a value of completed task. Was it approved or rejected ?
Please provide couple lines of code of replicator's ChildCompleted event to get anything out of Sequence activity instance (or any other way).
thanks
UPDATE: It seems in order to exchange values between instances of workflow you need to use DependencyProperty. So solution here is:
1) add DependencyProperty to parent workflow and add property which you will use to store value like this:
public static DependencyProperty childStatusProperty =
System.Workflow.ComponentModel.DependencyProperty.Register("childStatus",
typeof(string), typeof(parentWorkflowTypeName));
public string childStatus
{
get
{
return (string)base.GetValue(childStatusProperty);
}
set
{
base.SetValue(childStatusProperty, value);
}
}
2) in custom sequence activity access parent's instance and use defined DependencyProperty to set property to value like this:
private void completeTask1_MethodInvoking(object sender, EventArgs e)
{
var replicator = this.Parent;
var workflowParent = (parentWorkflowTypeName)replicator.Parent;
workflowParent.childStatus = "my custom status value";
}
3) read this value using normal property:
//from parent workflow
string status = childStatus;
The issue is that you have to record somewhere the list of all tasks created. I guess you are creating the tasks in parallel (not sequential).
I had the same issue, it took me a while to fix this.
Please check this link as a good starting point: http://rmanimaran.wordpress.com/2010/12/02/sharepoint-workflow-replicator-parallel-approval-problem-solution/

Sharepoint 2010 email event receiver

I am creating an email event receiver for sharepoint 2010 for a document library that receives emails in and I want to be able to then copy those emails that are sent to that list to another one. Now how would I go about doing that using an email event receiver rather than a itemAdded event receiver? what object methods can I use to get a copy method to another list etc?
SPEmailEventReceiver has the EMailReceived method.
When you take the MSDN example code:
public class Email_Handler: SPEmailEventReceiver
{
public override void EmailReceived(
SPList oList,
SPEmailMessage oMessage,
string strReceiverData)
{
SPListItem oListItem = oList.Items.Add();
oListItem["Title"] = oMessage.Headers["Subject"];
oListItem["Body"] = oMessage.HtmlBody;
oListItem.Update();
}
}
You see that they add the list item to the list via oList.Items.Add() which is exactly what you can do. You could also add the item to any other list.
Once you have the list item you could copy it to any other list by using the SPListItem.CopyTo method.
A good example for an EMail event receiver: http://pholpar.wordpress.com/2010/01/13/creating-a-simple-email-receiver-for-a-document-library/

Resources