How to transform a Kentico Email Template without sending it? - kentico

My Kentico server is unable to send e-mails, so I have to transform my e-mail using MacroResolver, but send it using some other way.
var clients = new List<Client>();
var macroResolver = MacroResolver.GetInstance();
macroResolver.AddDynamicParameter("clients", clients);
var emailMessage = new EmailMessage {
From = "someone#somewhere.com",
Recipients = "otherone#somewhere.com",
Subject = "Whatever"
};
var template = EmailTemplateProvider.GetEmailTemplate(templateName, siteName);
EmailSender.SendEmailWithTemplateText(siteName, emailMessage, template, macroResolver, true);
In other words, I would like to use Kentico just as a Template Engine. Is there anyway to achieve this?

What SendEmailWithTemplateText method basically does is it fills empty fields of message by its equivalent from a template and resolve macro values in it. If you are only after message body, then you can create the email message by:
emailMessage.Body = macroResolver.ResolveMacros(emailMessage.Body);
emailMessage.PlainTextBody = macroResolver.ResolveMacros(emailMessage.PlainTextBody);
For most scenarios it's also better to tell the resolver to encode resolved values. You can do it by: resolver.EncodeResolvedValues = true;
Also you are passing whole 'clients' collection to the resolver. You'll probably need to take it one by one and generate emails in a loop.

Related

Retrieve Documents from a Template

I created a template within my DocuSign developer Sandbox that contains one document. I'm using the C# SDK to try and send out an envelope to a user, based on a template.
Here's the code where I retrieve all of the templates.
TemplatesApi templateApi = new TemplatesApi(ApiClient.Configuration);
EnvelopeTemplateResults templateResults = templateApi.ListTemplates(AccountID);
The issue I am having is the EnvelopeTemplateResults does NOT have any documents associated with it.
When I use the REST API using POSTMAN, performing a GET to this URL, I can see that there's an envelopeTemplateDefinition, that has a Document on it, which is the one I want.
My question is, how, using the SDK API, can I get the envelopeTemplateDefinition ?
In order to have the ListTemplates method include the Documents info, you have to set an Include parameter:
var templatesApi = new TemplatesApi(apiClient.Configuration);
var listTemplatesOptions = new TemplatesApi.ListTemplatesOptions { include = "documents" };
var templateResults = templatesApi.ListTemplates(accountId, listTemplatesOptions);
If you are trying to get the Template Definition of a single template, the templatesApi.Get() method can be used with its own set of Include options:
var getTemplateOptions = new TemplatesApi.GetOptions { include = "documents" };
var templateDefinition = templatesApi.Get(accountId, templateId, getTemplateOptions);
Finally, if you're trying to get an actual PDF out of a specific template, that would be the templatesApi.GetDocument() method:
templatesApi.GetDocument(accountId, templateId, documentId);
Where DocumentId is the specific document you want to pull, or "Combined" if you want to pull all the documents in as a single PDF.
Chris, if you are using the v2 API, there's an endpoint:
GET /v2/accounts/{accountId}/templates/{templateId}/documents/{documentId}
you can try it here - https://apiexplorer.docusign.com/#/esign/restapi?categories=Templates&tags=TemplateDocuments&operations=get
the c# SDK inside TemplateAPI has GetDocument() and UpdateDocument() methods

SuiteScript SCA - Validating a form field

I am attempting to validate a form field for an SCA (mont-blanc) site.
As I am not versed in SuiteScript code, but know Java, I simply need to know how to retrieve the POST value of a form field, so that I can do a check on the submission before submitting the form.
The below is not working - simply because I don't know the function / method to call to get the email address that is being submitted.
name: 'ContactUs',
create: function create( data ) {
try {
url = '<the-url>';
var email = nlapiGetContext.getEmail();
if (email.indexOf("qq.com") === -1) {
response = nlapiRequestURL(url, data);
responseCode = parseInt(respons...
To validate any field data you need to use client-script on the said record and based on your code and requirement, I think you want to validate Suitelet data(right?).
You can deploy client script on any record/suitelet and validate field data in saveRecord method. You can find client script help doc here.
Detecting the value in a data field in a submitted form is as simple as data['field_name']
In the above example - it would be:
name: 'ContactUs',
create: function create( data ) {
try {
url = '<the-url>';
**var email = data['email'];**
if (email.indexOf("qq.com") === -1) {
response = nlapiRequestURL(url, data);
responseCode = parseInt(respons...

Get Add my own content to gmail compose box using inboxsdk

I am developing a chrome addon and I want to append my own content at the end to mail content using InboxSDK. I am using the following code, but it's appending to my cursor position in Gmail Compose Box.
var cv = event.composeView;
cv.insertTextIntoBodyAtCursor('My Content');
also, I want to append content before sending mail. So, How I can achieve it using InboxSDK.
Thanks in advance
You could just get the whole messages body, modify and set the modified version as the new messages body. There is two ways to approach it.
1. getBodyElement()
Get the whole messages HTML and append whatever you want to append and set this as the new body HTML.
var $content = $(composeView.getBodyElement());
var $myContent = $('<div class="my_content">Hello World!</div>');
$content.append($myContent );
composeView.setBodyHTML($content.html());
2. getHTMLContent()
It would also work with the HTML string of the messages body.
var contentString = composeView.getHTMLContent();
var myContent = '<div class="my_content">Hello World!</div>';
contentString += myContent;
composeView.setBodyHTML(contentString);

Sending email from netsuite using freemarker template engine

Can someone help me to work my task on netsuite Sending email. The email body should be generated with the freemarker template engine using nlapiCreateTemplateRenderer. I try to used the sample on the help page in netsuite but it doesnt work. Can somebody explain or give me a example on this API.
By the way i can sent email using suitelet, my problem is the email body.
Thank you.
Provided that you have your scriptable template. This should run OK.
var emailTempId = 1; // internal id of the email template
var emailTemp = nlapiLoadRecord('emailtemplate',emailTempId);
var emailSubj = emailTemp.getFieldValue('subject');
var emailBody = emailTemp.getFieldValue('content');
var records = new Object();
records['transaction'] = '1'; //internal id of Transaction
var salesOrder = nlapiLoadRecord('salesorder', 1);
var renderer = nlapiCreateTemplateRenderer();
renderer.addRecord('transaction', salesOrder );
renderer.setTemplate(emailSubj);
renderSubj = renderer.renderToString();
renderer.setTemplate(emailBody);
renderBody = renderer.renderToString();
nlapiSendEmail(-5, 'email#domain.com', renderSubj, renderBody , null, null, records);
The new Scriptable Template that is using the FreeMarker only supports Entity, Transaction, Custom Record, Case, & Project Record. Other records might work but based on Answer Id: 32621 from the SuiteAnswers those record are the ones that will be supported.

Create a Google Task from a email

I was looking the way to create a Task from an email at my Google Account with a filter. I've read this tutorial and it worked like a charm: http://www.pipetree.com/qmacro/blog/2011/10/automated-email-to-task-mechanism-with-google-apps-script/
The only bad thing is that the script creates a task with the subject of the message, and it's not really descriptive for me, because they are automatic messages, and all of them have the same subject.
I want the Task Title be a specific line of the email body, can anybody helpme with this?
Yes, basically you would get the message body and extract what you need from it. I'm not sure about the structure of your email but you need something in there that tells you the start and end of the task title, once you tell me what it is i can incorporate it in to the code. For now this is how you would set the body as the title.
var message = thread.getMessages()[0]; // get first message
var messagebody = message.getBody();
var body_array = messagebody.split('Sender:');
var taskTitle = '';
if( body_array.length < 2 )
taskTitle = 'No title specified in email after Sender:';
else
{
var text = body_array[1];
taskTitle = text.split('<br />')[0].trim();
}

Resources