SpmShipment, how do I use it so it actually sends out a mailing automatically?

I have a customer who wants to create and send a scheduled mailing automatically.

With the shipment class I can create a shipment, and add recipients to it.

But the mailings are never sent out automatically. And the recipients are not really loaded. Only the lists are added.

So either something is not working as expexted or I am missing to add some important parameters or call some important script methods.

I cannot find them in the ClassObject but perhaps there are some un documented procedures I have to follow.

Anyone knows? I need help

(Also, there are quite a lot of paremeters that cannot be set by CRM script, so the API need to be updated)

Code needed:

DateTime dt;
//dt.addMin(1);

SpmShipment shp;
shp.addListCRMSelection(35);
shp.setDescription("GC Description 8 0 min");
shp.setFolderId(4);
shp.setFrom("support@test83.suocrm.eu");
shp.setMessage(22); //
shp.setSendRate(100);
shp.setStartDate(dt);
shp.save();

 

RE: SpmShipment, how do I use it so it actually sends out a mailing automatically?

I believe I can answer some of your questions:

 

To get the recipients to load in UI

After creating the shipment from CRMScript, click Edit and skip to step 4 Recipients.

If your Recipient sources are populated, click Update list in the lower right corner and wait for the list to reload.

At this point, you can click Next and either send now or schedule. 

If it is still empty, check your addresses.

Note that each email address must:

  • be valid
  • belong to someone registered in SuperOffice
  • have appropriate consent

The following code creates a raw message and a list with 1 address. Substitute the email addresses and selection ID with something valid in your tenant.

 

// create the message and save the ID
SpmMessage msg;
msg.setSubject("That or which");
msg.setBody("Is this a restrictive or non-restrictive clause?");
msg.setFolderId(-1);
msg.setDescription("Grammar 01");
Integer msgId = msg.save();

// create the recipient list and save the ID
SpmStaticList recipients;
recipients.setFolderId(-1);
recipients.setName("Novice authors");
recipients.addRecipient("me@address.com", "My name");
Integer listId = recipients.save();

// create the shipment and save the ID
SpmShipment myShipment;
myShipment.setFrom("sender@address.com");
myShipment.setMessage(msgId);
myShipment.addList(listId);
myShipment.addListSelection(4);
myShipment.setFolderId(-1);
myShipment.setDescription("Grammar lessons");
myShipment.setSendRate(10);
DateTime startDate;
myShipment.setStartDate(startDate);

Integer shipmentId = myShipment.save();

// Write debug info
print("Message ID: " + msgId.toString() + "\nList ID: " + listId.toString() + "\nShipment ID: " + shipmentId.toString() + "\n");

(This example is written for clarity rather than efficiency.)

 

To set extra parameters

Yes, not all parameters are not accessible to be set via the CRMScript SpmShipment class. Have you tried using the SearchEngine to update fields in the s_shipment database table ? For example, shipmenttype_id and reply_addr.

Scheduling

Unfortunately, I can't get it to schedule and send from the script either. You're probably right about there beging a bug here. We're looking into it.

Av: Bergfrid Skaara Dias 6. jul 2021

RE: SpmShipment, how do I use it so it actually sends out a mailing automatically?

FYI:

The SDK-group have reported this as a bug:

https://community.superoffice.com/en/product-releases/bugs-wishes/product-issue/?bid=15322&azure=1

 

Av: Marcus Svenningsson 7. jul 2021

RE: SpmShipment, how do I use it so it actually sends out a mailing automatically?

Thanks for the info Bergfrid, I also can't seem to get an SpmCustomerList working.

See your edited example;

SpmMessage msg;
msg.setSubject("That or which");
msg.setBody("Is this a restrictive or non-restrictive clause?");
msg.setFolderId(-1);
msg.setDescription("Grammar 01");
Integer msgId = msg.save();

// create the recipient list by adding persons to it
SpmCustomerList customerList;
customerList.setName("Test list 2");
customerList.setFolderId(-1);
customerList.addRecipient(9466); // ref to person
Integer recipientListId = customerList.save();

// create the shipment and save the ID
SpmShipment myShipment;
myShipment.setFrom("sender@address.com");
myShipment.setMessage(msgId);
myShipment.addList(recipientListId);
//myShipment.addListSelection(4); // why?
myShipment.setFolderId(-1);
myShipment.setDescription("Grammar lessons");
myShipment.setSendRate(10);
DateTime startDate;
myShipment.setStartDate(startDate);

Integer shipmentId = myShipment.save();

// Write debug info
print("Message ID: " + msgId.toString() + "\nList ID: " + recipientListId.toString() + "\nShipment ID: " + shipmentId.toString() + "\n");

 

 

Av: David Hollegien 9. jul 2021

RE: SpmShipment, how do I use it so it actually sends out a mailing automatically?

That seems to be another bug, @David. Thanks for pointing it out.

However, I do have a workaround for you in this case :)

You can create a selection from the CRMScript based on the person IDs and then use that when populating the shipment.

NSSelectionAgent agent;
NSSelectionEntity selection = agent.CreateDefaultSelectionEntity();
selection.SetName("CRMScript selection test");
selection = agent.SaveSelectionEntity(selection);
Integer selectionId = selection.GetSelectionId();

NSContactPersonId[] contactPersons;

for (Integer i = 1; i < 20; i++) {
  NSContactPersonId id; 
  id.SetPersonId(i);
  contactPersons.pushBack(id);
}

agent.AddContactSelectionMembers(selectionId, contactPersons);
selection = agent.SaveSelectionEntity(selection);

// ...

myShipment.addListCRMSelection(selectionId);

 

Here, I've just used a for-loop to create some dummy data. You could alternatively use an Integer array with the actual IDs and loop through that.

Again, this code is not optimized for production performance.

Av: Bergfrid Skaara Dias 9. jul 2021

RE: SpmShipment, how do I use it so it actually sends out a mailing automatically?

I have also registered a wish to make all settings available via the SpmShipment class.

https://community.superoffice.com/en/product-releases/bugs-wishes/product-issue/?bid=15397&azure=1

Av: Bas Kreijveld 12. jul 2021