Create a Google Task from a email - gmail

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();
}

Related

Delete emails from a label after certain number of days

I am a true novice at this. Needed a solution to clean up my gmail.
After searching found the script below. I created filters that send emails to the "delete me" label. I added the script to my projects and published giving it access to my gmail. I also set up a hourly trigger. The filters are working well and the script is running based on the log but no emails are getting deleted.
Can anyone tell me what's wrong? (I made a similar one for a label called "archive me" and this is also not working).
Thank you
function cleanUp() {
var delayDays = 60
var maxDate = new Date();
maxDate.setDate(maxDate.getDate()-delayDays);
var label = GmailApp.getUserLabelByName("delete me");
var threads = label.getThreads();
for (var i = 0; i < threads.length; i++) {
if (threads[i].getLastMessageDate()<maxDate)
{
threads[i].moveToTrash();
}
}
}

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);

SuiteScript Script sending statements

I couldn't find an answer to this in docs or here. Is it possible to script sending statements to customers? thanks for any help you can give.
Yes, but it's even easier to do it with a workflow. We created a custom field for a 'Statement Contact' and set up a scheduled workflow based on a 'Saved Search Filter' which basically checks that the customer has a balance. There is one state which contains a single 'Send Email' action. The 'Send Email' action has the option to 'Include Statement'. It fires on the 4th day of each month - you can set this or any other parameter to whatever suits you. This works fine for us, so I hope it helps you.
I found this in SuiteAnswers, it is enough for my purposes.
function printStatement()
{
//this is is the customer id
var id = nlapiGetRecordId();
var email = nlapiGetFieldValue('custentity_accounting_email');
//create an array to set the STATEMENT properties(optional)
var sdate = new Array();
sdate.startdate = '11/01/2015'; // replace it as per requirement
sdate.statementdate = '11/30/2015'; // replace it as per requirement
sdate.openonly = 'T'; // replace it as per requirement
sdate.formnuber = 112; // replace it as per requirement
//print the statement to a PDF file object
var file = nlapiPrintRecord('STATEMENT', id, 'PDF', sdate);
//send the PDF as an attachment
nlapiSendEmail('-5', email, 'Regular Statement', 'Please see attached Statment', null, null, null, file); //change the value of author id.
}

Creating a shortcut for Gmail canned response

I'm currently using Gmail Lab feature - canned responses. I have a lot of these canned responses and using their menu to find the right one, proves to be time-consuming. It would be way easier to find a canned response by:
linking a canned response to a keyword
using that keyword in the body or subject field. Something like this.
Would this be possible by using Gmail API or would you suggest another way to do it?
How is this workflow? Add the label "CannedResponses" to all your prepared replies. Then mark each with the particular label the reply applies to, eg 'TestLabel1'. Then as new emails come in you label them, and after that you run a script like this:
function CannedReply() {
var label = "<mylabel>"; //eg <myLabel> = TestLabel1
var myemail = "<me#gmail.com>";
var responsebody = GmailApp.search(
"label:" + label + " label:CannedResponses"
)[0].getMessages()[0].getBody();
var threads = GmailApp.search("label:" + label + " -label:CannedResponses label:unread");
for (var i = 0; i < threads.length; i++) {
for (var j = 0; j < threads[i].getMessageCount(); j++) {
message = threads[i].getMessages()[j];
message.reply("", {htmlBody: responsebody, from: myemail});
GmailApp.markMessageRead(message);
}
}
}
using that keyword in the body or subject field
Autohotkey would support this, it's an app that lets you map key combinations or keywords to text macros. You wouldn't be using any native Gmail features this way, including their canned responses feature, but it might suit your need well enough.

How to transform a Kentico Email Template without sending it?

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.

Resources