google app script sending mail as PDF issue - google-apps-script

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.

Related

Google apps script - UrlFetchApp to get image blob gets timeout error

I have created a script to automatically send a subscription-confirmation e-mail when a client submits a form.
In the e-mail, I embed an image that is fetched from my website with the UrlFetchApp class (https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app).
var logoUrl = "https://my.site.com/path/to/logo.png"
var logoBlob = UrlFetchApp.fetch(logoUrl).getBlob().setName("logo");
...
MailApp.sendEmail({
to: client.email,
subject: "...",
htmlBody: // html with reference to image like this:
"<img src='cid:logo' width='107' height='160'/>"
,
inlineImages: {
logo: logoBlob,
}
});
Since last week, this UrlFetchApp line causes a time-out error (error message in Dutch):
Time-out: https://my.site.com/path/to/logo.png (regel 4, bestand 'inschrijvingsbevestiging', project 'inschrijvingsbevestiging')
This has worked before without any problem, the image file also is accessible from the given URL with a browser.
I'm new to javascript and google-apps-scripts so I have no idea where to start searching for a solution. The reference manual does not mention the time-out.
Any ideas on how to solve this?
EDIT When I change the logoUrl path to some other image (I tried "https://www.google.be/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png", the script works fine. So maybe there is a problem with my site?
EDIT 2 Since the script works fine with another logo, the problem must lie on my webhost. I worked around the problem by putting the logo on my Drive, as suggested in the comments.

SitesApp.getActivePage() always return landing page

I use the following function:
function doGet(e) {
Logger.log( SitesApp.getActivePage().getName())
}
It always returns the name of the home page
This seems to be an issue with Google currently. All Google Sites are facing this issue. Please submit a bug report, and cross your fingers it'll be solved soon.
Here is an existent bug report of this issue. Please +1 it to give it more attention.
There is an older discussion about this issue here Apps Script .getActivePage() only returning "home" page
which suggests the problem can be related to using setHtmlContent() when the embedded html gets modified. There has been a recent problem with htmlbox on Google Sites for which a fix is in the process of rolling out which may have some bearing on this issue
Hi I have the same issue. My script worked on Old Google Site, but it doesn't work anymore on a new Google Site.
And the issue in this code:
var pageUrl = SitesApp.getActivePage().getUrl();
My question is almost the same: How to get URL of the current page on the New Google Site with GAS?
google.script.url.getLocation
google.script.url.getLocation(function(location) {
console.log("locations:----------------------------------------");
console.log(location);
console.log(location.parameters);
console.log(location.hash);
console.log("----------------------------------------");
});
The code above gives the next output:

Insert HTML into email in Apple Mail

Is there a way to insert pure html into an email via Apple’s desktop Mail app (ie. creating a newsletter, tables, etc.)?
I know you’re able to do this on Mac OS via Thunderbird, just wondering if there’s a reliable method or extension for Apple Mail specifically.
Having been seeking for solution for so long.
Both cmd + a then cmd + c or cmd + i in Safari may drop some style/script. Occasionally I found a nealy perfect solution by myself.
Create a new mail in apple "Mail.app", write anything then hit cmd + s.
Find your draft at the left panel of "Mail.app". Drag it onto your desktop.
Edit the draft file with any text editor you like. See some html source code at the bottom of the draft file? Replace them with the html code you want to send then save the file.
Open "File" - "Import Mailboxes" in "mail.app". Select "Apple Mail", import the
edited draft file.
You will see your mail at the left panel of "Mail.app". Drag it into a "Draft" mailbox.
Finally open the mail, fill in To, CC, Subject, etc, and send your pure HTML mail.
There is a "simple" way : open your html content in Safari, then press command + i
The html content of the page will be inserted in the body of a new mail message.
I was also looking for a solution and found this thread. Here is how I paste code into Apple Mail:
Copy your code into the code beautifier at http://hilite.me/. Then save the generated HTML to a file and open that in Safari and Press command + i as Creaforge said (thanks for the tip).
To expand on what TheycallmeXiaoli said :
Create a new mail in apple "Mail.app", write Bonjour then hit cmd + s.
Find your draft at the left panel of "Mail.app". Drag it onto your desktop.
Edit the draft file with any text editor you like (ex: TextEdit)
Search for the word Bonjour you wrote earlier - Replace ONLY this Bonjour with your ENTIRE html code
then save the file.
do not delete anything else ! don't replace the current HTML tag just the word Bonjour
In the Mail App Select File -> Import Mail Boxes
Select "Apple Mail" & import the edited file.
You will see your mail at the left panel of Mail App
most likely inside an "imported" folder
Drag the file into your "Draft" mailbox.
Finally open the mail, fill in To, CC, Subject, etc, and send your pure HTML mail.
: )
Thanks so much TheycallmeXiaoli !

How to show a preview of a file on a panel in a UiApp using GAS

I want to display a preview of a(ny) file on a panel in a UiApp using GAS.
I'm using DriveApp, not DocsList.
Using file.getThumbnail() or file.getAs(mimeType) I can get a Blob of any file.
Documentation at https://developers.google.com/apps-script/reference/drive/file#getThumbnail%28%29 states that (at least) I can get those blobs being converted to 'application/pdf'.
I don't know how to display those blobs (or pdf-files as such) on a panel.
Can anybody tell me what I should do?
You cant display them inside the panel because you would need to iframe it, which isnt possible even with htmlServices.
Use an anchor to open the link on another page. You can link to the original file.
You can convert a spreadsheet with a pdf but i don"t know with any File.
I use this code
var pdf = DocsList.getFileById(newSpreadsheet.getId()).getAs('application/pdf').getBytes();
var attach = {fileName:'Weekly Status.pdf',content:pdf, mimeType:'application/pdf'};
You cna test It with this source if he can help you .
https://gist.github.com/ixhd/3660885

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