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).
Related
With the Google Apps Script Gmail library, when I use the function GmailMessage.getPlainBody(), the API seems to take what used to be one paragraph and break it up into multiple, potentially by using a character limit. For instance, a paragraph of my email reads:
From the link you sent me, I gleaned that Gmail refers to their secure email as confidential.
But when I call this function on the email, it becomes:
From the link you sent me, I gleaned that Gmail refers to their
secure email as confidential.
And, when I split the email text on a new line delimitor and do a bit of cleanup to create an array with my output, I end up with:
['From the link you sent me, I gleaned that Gmail refers to their', 'secure email as confidential.']
I viewed this Reddit post, which seemed to deal with the similar problem. But, I tried the resolution suggested by the person who posed the question:
body = message.getPlainBody().replace(/\r\n\r\n/gm,'aaaLINEBREAKERaaa').replace(/\r\n/gm,' ').replace(/aaaLINEBREAKERaaa/gm, '\r\r').replace(/ /gm,' ')
And it didn't quite give me what I need. Has anyone else encountered this problem, and if so, do you have a suggested workaround? Thanks!
I had the same issue. In that case, I used a workaround.
When I checked the email, I noticed that the HTML body is included in the message body and the HTML body has the original paragraph, and I used this situation. So, in this workaround, the original text is retrieved from the HTML body and the HTML is converted to a text. By this, the original paragraph is obtained. The sample script is as follows.
Sample script:
This script uses Drive API for converting HTML to text. So pelase enable Drive API at Advanced Google services.
var message = // Here, please use your "message".
var html = message.getBody();
var id = Drive.Files.insert({title: "temp", mimeType: MimeType.GOOGLE_DOCS}, Utilities.newBlob(html, MimeType.HTML)).id;
var text = DocumentApp.openById(id).getBody().getText(); // or DocumentApp.openById(id).getBody().getText().trim();
DriveApp.getFileById(id).setTrashed(true);
console.log(text)
References:
getBody()
Files: insert
I want to import data from a table from the following page:
https://basketballmonster.com/playerrankings.aspx
When I do so, with all players filter selected, only the top players are imported to my googlesheet. Can someone help me achieve this? Appreciation in advance.
I attached the googlesheet below for your review:
https://docs.google.com/spreadsheets/d/1uvhNp6gBnnEvs8CBb4K7onccew_doFp96wmFEsYyLBk/edit?usp=sharing
Google Sheets can't know what your browser has, so it doesn't know whether you selected which filter. You have to get the same html for Sheets that you have displayed in your browser, which means adding the filter in your query.
Since it looks like the controls aren't passed as parameters in a GET request, sadly it's not as simple as appending
?PlayerFilterControl=TopPlayers to the url.
You have to POST it as a payload with a post request like
{ 'PlayerFilterControl': 'AllPlayers'}.
Sadly Google Sheets IMPORTHTML() doesn't support post request yet, so you'll have to get into apps scripts, request and xml parsing.
I suggest you check out these:
https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app
https://developers.google.com/apps-script/reference/xml-service
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.
A script was working fine 6 months ago and now is creating me some issue when sending a doc as pdf...-> My pdf loose his layout.
I am not loosing the doc's layout when i send the mail manually using (from the menu) file ->Email as attachment -> choose pdf
but when i use this (a script.) i've got 25 extra pages and i loose the oirginal layout of the document.
var fileq = DriveApp.getFileById('17Fj7JfYkQk9blablabla');
MailApp.sendEmail('somemail', "Attachment example", "blablabla", { name: 'Automatic Emailer Script', attachments: [fileq.getAs(MimeType.PDF)] });
What is going on ?
thanks for help,
another problem:
The problem occurs even when downloading more than 1 doc in pdf at time...very wierd..
The only thinhs who works in extract 1 file to pdf at time manually...all other stuff (scripting or manually) just modifiy the layout.
May be this problem is related only for big file..my docs are 20 to 25 pages long.
Who knows ?
Thanks for help anyway
The problem did not ocurr with me. You can see the sample here.
Please change the document ID in this script and run again sending to my mail and I will check the results.
It adding to me 24 extra page..changing the layout of the entire original document.
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