Gmail apps script getBody/getPlainBody without signature? - google-apps-script

I'm calling messages[j].getPlainBody(); to output the body of an email and log it in a spreadsheet. I want to log the plain text of the email - not the signature, footer etc from the email. How can I do this?
I notice in Gmail there's a sort of tab that hides my signature when I'm writing/viewing emails - can I access this programmatically somehow to achieve the above?

The Gmail UI intelligently collapses the messages to hide previous messages or signatures. There is no way to do this in the API. You can log an enhancement request here - https://code.google.com/p/google-apps-script-issues/issues/list

Related

Want to create a link I can send people that will open their email app with a pre-written message (NOT A LINK ON MY OWN WEBPAGE OR APP)

I am trying to replicate something someone has done in this link https://l.instagram.com/?u=http%3A%2F%2Ftinyurl.com%2Fyd49a4ow&e=ATMn3WfYRw5VZzFDz9FU9Pp0jqk5uBpX0Vo4n2MffH-mr8W5f84IEmpo-Rbx3neyIU0ehQcntNJuRsSGfW9bjw&s=1.
When on a mobile app the link opens the mail app with a pre-written email body subject and recipients.
It is similar to the mailto function if I were designing my own web page and using HTML but this is a link I want to be able to email and share with people.
Thanks so much for your help!
Checkout mailto links: https://css-tricks.com/snippets/html/mailto-links/
The long-and-short of it is that you can make a link that looks like this:
Email Us
Basically, you are using the link's query parameters to preset the subject line, recipient, and body of the email.
Build your link like so:
mailto:<the *recipient's* email>?subject=<subject line>&body=<email content>
Then you can add the following options:
Carbon Copy (cc) and Blind Carbon Copy (bcc)
Each email must be separated by a comma (&cc=email#example.com, email2#example.com)
Subject (subject)
Email body text (body)
Make sure to URL-encode the subject and email body text as well.

Embedded Google form in email?

I'm embedded Google form in email by Google apps script but the form doesn't submit correctly from Outlook and from iPhone. It works from Google Mail client only?
Is there's away to solve this problem of submission from iphone or outlook?
Thanks
Amany
To use forms embedded in emails, the email client needs to support html forms. Outlook has its own forms, but does not support the html form element (reference). I haven't found a reference for iPhone, but it's likely that it also limits the html support. (I use the gmail client on my phone... it supports forms.)
If you're using the code from Send form by email and track responses in spreadsheet, then you can extend your script to provide a doGet function for users that don't have HTML Forms support in their email clients.
The previous gist has been updated with these changes. (Actually, the gist already had the doGet() function.)
Code.gs
Extend this code by adding a doGet() function, which will host the exact same form that you're embedding in the email.
/**
* GET handler to provide alternate online form.
*/
function doGet() {
// Build survey body
var template = HtmlService.createTemplateFromFile('emailTemplate');
template.scriptUrl = ScriptApp.getService().getUrl();
template.serialNumber = getGUID(); // Generate serial number for this response
var app = template.evaluate();
return app;
}
Make the following modification to the sendSurvey() function:
var plainText = 'Please complete this survey online at: ' + scriptUrl;
html += '<p>Alternatively, you may complete this survey online.';
// Send email form
GmailApp.sendEmail(recipient, subject, plainText, {htmlBody:html} );
Now, recipients without HTML support in their email client will have a plain text message with an address they can paste into a browser, while HTML clients without <FORM> support will have a clickable link to the online form.

Google Spreadsheet Script Editor MailApp.sendEmail not setting replyTo?

I'm using Google Spreadsheet for customers to send in comments. When they submit a comment, it gets emailed to me. I use the MailApp.sendEmail method. It works as expected except for the replyTo "advanced argument":
var myAdvancedArgs = { htmlBody: myHtmlBody, replyTo: customerEmail };
MailApp.sendEmail("me#example.com", "Comments Form", myBody, myAdvancedArgs);
customerEmail is set properly because I have it output correctly in the body of the message. htmlBody works as I do get the HTML version of the email displaying in my GMail account. However, when I click the reply button in GMail, the To: address is myself. It appears the replyTo is not being set at all. But then I look in the headers of the email message by clicking the little triangle next to my name with the tooltip "Show Details" and it does mention the correct reply-to address:
reply-to: mycustomer#example.com
Is MailApp.sendEmail not setting the reply-to header correctly?
UPDATE: I've snipped a couple images to demonstrate what's happening. Either the reply-to header isn't set properly (maybe that's not how you do a reply to?) or GMail is not working properly for me.
First image, you see that there is a reply-to header created from my Google Spreadsheet script:
Second image, when I click the reply button in GMail, the to address is not filled in with the address in the reply-to header:
I found the reason to your (and my) problem.
What you are seeing is a Gmail bug, not an Apps Script bug. Basically,
if the reply-to is any email address that you have linked with your
address so you can send mail as that account from within gmail, then
reply-to is ignored. In other words, it will look broken to you, but
for any other users of your script it will work properly. Non-Gmail
users will see it work correctly in any case.
This is an old question, but if I needed it maybe others also need it!
From my testing the replyTo worked only when I sent the mail not to the form Acount mail.
If your form is on your#gmail.com acount send it to yourOtherMail#gmail.com
var reply = e.namedValues['Email'];
MailApp.sendEmail("NotFormMail#mail.com", "subject", "message",{"replyTo" : '"'+reply+'"'});
Just tested like this :
function myFunction() {
MailApp.sendEmail("serge----#gmail.com ", "test message",'empty body', {"replyTo" : "serge_test#yopmail.com"}); // replyTo son#insas
}
and it works as expected when I "reply" (using the reply button in gmail or in any mail client ) it shows up like this :
which is indeed the replyTo adress even if it is true that the sender is indeed the author of the script (which is also the expected behavior, see documentation about scripts)
So I'm afraid the issue you raised is invalid...

Customise email before sending

I am recoding a friend's artist/client booking system. I have little experience in programming, enough understanding to hack my way through and google has been a great help!
I've spent the last 3 days reading and searching... Havn't found anything on that... Maybe I'not using the proper terms....
Here's what I want to do.
I use Google Script and google spreadsheet. 1 row contains all the information about a specific contract.
I want to be able to use a menu item to generate the contract (completed)
Open 2 browser window
one to display the Contract PDF file ( completed )
one for a GMAIL New email
with the contract pdf attached ( completed )
generated email body from selected row in the spreadsheet( completed )
be able to customize the generated email text before
sending it. Adding attachements...
This is what I'm stucked at. I use
MailApp.sendEmail('xxx#yyy.com', 'transfer email as pdf : body
& attachment', 'see attachment', {attachments:[body_to_send]});
It send's the email ok, with attachement and generated body and all... but no way to edit the email before sending...
Is that possible with google script?
Explore the UiApp class in Google Apps Script. UiApp
You could build a simple UI where the user can enter additional content and upload files, which can then be appended to the email before sending.
It doesn't look like Apps Script supports creating email drafts, which would also provide a way for you to edit emails before sending them. (Sending an email to yourself with a fancy way to reference the ultimate recipient is another possibility using the native Gmail UI.)
Is this in the direction you were thinking?
The last step of your process can be achieved using a Google Doc template in which you can add whatever you want to improve presentation.
From there you get an html version of your doc and use it as a html body in your mail.
If you need more details about html import you'll find it easily on this forum and on the issue tracker.
You could also run this code from a document bound script in a sidebar which would be visually more convenient. (see my recent posts about mailmerge).

How to access or call "Send this form to others"?

I have a form attached to a Google Apps spreadsheet. It's a form to let my coworkers submit agenda items to our weekly review meeting. I'm writing a script to automatically email a reminder to the relevant people.
To make it less annoying & tedious for them, I'd like to actually embed the form within the email. Google Docs provides a way to manually send a form: Spreadsheet > Form > Send form. However, I can't find any way in the Google Apps Scripts documentation that lets me trigger this functionality, e.g.
A method like sendFormInEmail
Access to the email-friendly form HTML, which I could assign to the htmlBody argument of the sendEmail method.
Trigger an arbitrary menu item in Google Apps
Something else?
I could do a workaround by extracting the generated HTML from an email and assigning it as the htmlBody argument, but then I'd have to manually update the html every time we want to make a change to the form -- not what I want to happen.
Any suggestions?
Joris, you're right. You can use the method fetch() to send the form's html to the user's mailbox:
var form = FormApp.create('New Form');
....
var url = form.getPublishedUrl();
var response = UrlFetchApp.fetch(url);
var htmlBody = HtmlService.createHtmlOutput(response).getContent();
MailApp.sendEmail({
to: email,
subject: subject,
htmlBody: htmlBody,
});
...
I have the exact same requirement as you do, but unfortunately there doesn't seem to be an API call that does this.
What I think might work (though I have yet to actually try this) is to use the Spreadsheet.getFormUrl method to get the form URL, then use UrlFetchAp.fetch to obtain the HTML for the spreadsheet form, and then use that HTML as the e-mail body.
Like I said, I don't know if this will work (though on paper it should!), but I'd be very interested to know if it did!