I am reading all files from a folder on my server and need to imbed them in the body of a email with phpmailer, - phpmailer

I need to embed several pictures in the same email. I am reading them from a folder with a for each loop. And it embeds the same file over and over. If I attach them, it works as it should. But my client wants them embedded. I think it is because they all have the same CID: tag But I cant figure out how to fix that, here is the code.
$dir = "$mypath*";
foreach(glob("$dir") as $files21){
$mail->AddEmbeddedImage("$files21", "attach", "$files21");
$body.='<img alt="PHPMailer" src="cid:attach"> ';
}
$dir = "$mypath_pdf*";
foreach(glob("$dir") as $files22){
$mail->AddAttachment( $files22 );
}
The bottom code attaching the pdfs works great just not the embeding the jpgs part.
So it reads all jpg files but just embeds the same one over and over.

Related

Im am getting FileNotFoundError when trying to create a for in loop

I am making an image classifier. I have successfully created the folders and I manually placed the .txt files which has links to images from google inside each folder.
I am now trying to download the images from each .txt file either into a folder inside each folder category, or into each category folder that also has the .txt file, however i keep getting errors. please help.
I manually placed the .txt files in each of the folders as they was in the parent folder name as PLANTS but this has not made a difference.
I expected to get all the images downloaded in their respective folders from the .txt files with google image links but it is not working, whether the .txt is inside the main PLANTS FOLDER or inside each category folder which is inside the PLANTS folder
instead i get the below errors
FileNotFoundError
please see attached screen shot
&
Long filenames or paths with spaces are supported by NTFS in Windows NT. However, these filenames or directory names require quotation marks around them when they are specified in a command prompt operation. Failure to use the quotation marks results in the error message.
for i in range(len(folders)):
path = "content/gdrive/My Drive/Colab Notebooks/Flowers/PLANTS"
#for creating directory we need path class object so below this:
dest_for_creating_directory = path/folders[i]
#for searchi directory which have spaces we need doubleQuotations that
#why user below one in download image function instead of dest.
dest_for_searching_directory = path+"/"+folders[i]
Note: its better practice to write folder/file name without space more info

How can i make 'text' to 'downloadable url'?

I make chrome extension, which download some files from website.
i want write some log with txt file, because my program has some error and i want save error to txt file.
but i can't find how to do it.
someone say it's impossible.
i try to search, some questions say just 'app' can do it, but extension can't.
if i want this functions, i must change my program to web app? but i don't know anything about that...
'download file' is possible, download is write file to filesystem.
i think, 'write text file' is so easy work then download image and sound files....
why not??? what's diffrent??
i see many questions, blog and document, but i cant know clearly.
*to sum up
I want make some text to downloadable file. If i can get downloadable file and it's url, everything is perfect.
i see this extension, i think i can do it. but i don't know how to do it.
please teach me how do it!
https://chrome.google.com/webstore/detail/save-text-to-file/mkepenkbhepjelljcfiooignmpfgochi/related
This is what I understand from your question that you want to write some text into .txt file and it should be automatically downloaded for your users. For that, here I am writing code in JavaScript which will surely helps you.
var fileText = "Your content which you want to save in file";
var fileBlob = new Blob([fileText], {
type: 'text/plain'
});
var fileUrl = URL.createObjectURL(fileBlob);
var fileName = 'mytextfile.txt';
var fileOptions = {
filename: fileName,
url: fileUrl,
conflictAction: 'uniquify'
};
fileOptions.saveAs = true;
It will automatically download mytextfile.txt file with your given contents. You can implement this logic in your chrome extension as per your way.

Can't get to exif data .JPG image

I'm trying to read the exif data from a .JPG image. I've tried differents solutions found here and there (PIL, piexif, exifread...) and none of them worked for this set of images. It worked for other images taken from another camera but not for this one, all these different methods returning empty dictionaries. It seems that there is no exif data but (I apologies for my newbyness) when I RIGHT-click + properties (I use windows), I do see what is exif data to me : date of creation, etc...
Here is one image :
image.JPG
If another of the thousands of anonymous heroes could help me on this one, I would be very grateful...
Alright so I found a solution which I share now.
The problem is that the libraries that open metadata are not taking all possible configurations for the image file and therefore, they can handle some and some others they cannot. I finally made it using exiftool, an executable that I dowloaded on my windows on this link :
https://sno.phy.queensu.ca/~phil/exiftool/
Then I paste the executable in a folder and I add exiftool.py in that folder, that I got from :
https://github.com/smarnach/pyexiftool/find/master
Then, using this small piece of code (for example):
import exiftool
with exiftool.ExifTool("exiftool.exe") as et:
metadata = et.get_metadata_batch(files)
for d in metadata:
print("{:20.20} {:20.20}".format(d["SourceFile"],
d["File:FileCreateDate"]))
Of course, this is just to show that you indeed can access the metadata, then you can do whatever you want with that. Here is the documentation of the library exiftool : http://smarnach.github.io/pyexiftool/
Cheers, JM

Backup Google Drive to .zip file with file conversion

I keep going in circles on this topic, and can't find an automated method that works for mass data on a Google Drive. Here is the goal I'm looking to achieve:
My company uses an unlimited Google Drive to store shared documents, and we are looking to backup the contents automatically. But we can't have the data stored in a backup with google documents like ".gdoc" and ".gsheet"... we need to have the documents backed up in Microsoft/Open-Office format (".docx" and ".xlsx").
We currently use Google's Takeout page to zip all the contents of the Drive and save it on our Linux server (That has redundant storage). And it does zip and export the files to the correct formats.
Here: [https://takeout.google.com/settings/takeout][1]
Now that works... but requires a bit of manual work on our part. And babysitting the zip, download and upload processes is becoming wasteful. I have searched and have read that the google API for Takeout is unavailable to use through gscript. So, that seems to be out of the question.
Using Google scripts, I have been able to convert single files.... but can't, for instance, convert a folder of ".gsheet" files to ".xlsx" format. Maybe copying and converting all the google files into a new folder on the drive could be possible. Having access to the drive and the converted "backup", we could then backup the collection of converted files via the server...
So here is the just of it all:
Can you mass-convert all of a google drive and/or a specific folder on the drive from ".gdoc" to ".docx", and ".gsheet" to ".xlsx". Can this be done with gscript?
If not able to via the method in question one, is anyone familiar with an Linux of Mac app that could do such a directory conversion? (Don't believe it because of googles proprietary file types)
I'm stuck in a bit of a hole, and any insight to this problem could help. I really wish Google would allow users to convert and export drive folders via a script selection.
#1) Can you mass-convert all of a google drive and/or a specific folder on the drive from ".gdoc" to ".docx", and ".gsheet" to ".xlsx". Can this be done with gscript?
You can try this:
How To Automaticlly Convert files in Google App Script
Converting file in Google App Script into blob
var documentId = DocumentApp.getActiveDocument().getId();
function getBlob(documentId) {
var file = Drive.Files.get(documentId);
var url = file.exportLinks['application/vnd.openxmlformats-officedocument.wordprocessingml.document'];
var oauthToken = ScriptApp.getOAuthToken();
var response = UrlFetchApp.fetch(url, {
headers: {
'Authorization': 'Bearer ' + oauthToken
}
});
return response.getBlob();
}
Saving file as docx in Drive
function saveFile(blob) {
var file = {
title: 'Converted_into_MS_Word.docx',
mimeType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
};
file = Drive.Files.insert(file, blob);
Logger.log('ID: %s, File size (bytes): %s', file.id, file.fileSize);
return file;
}
Time-driven triggers
A time-driven trigger (also called a clock trigger) is similar to a cron job in Unix. Time-driven triggers let scripts execute at a particular time or on a recurring interval, as frequently as every minute or as infrequently as once per month. (Note that an add-on can use a time-driven trigger once per hour at most.) The time may be slightly randomized — for example, if you create a recurring 9 a.m. trigger, Apps Script chooses a time between 9 a.m. and 10 a.m., then keeps that timing consistent from day to day so that 24 hours elapse before the trigger fires again.
function createTimeDrivenTriggers() {
// Trigger every 6 hours.
ScriptApp.newTrigger('myFunction')
.timeBased()
.everyHours(6)
.create();
// Trigger every Monday at 09:00.
ScriptApp.newTrigger('myFunction')
.timeBased()
.onWeekDay(ScriptApp.WeekDay.MONDAY)
.atHour(9)
.create();
}
Process:
List all files id inside a folder
Convert Files
Insert Code to a Time-driven Triggers
2) If not able to via the method in question one, is anyone familiar with an Linux of Mac app that could do such a directory conversion? (Don't believe it because of googles proprietary file types)
If you are want to save it locally try setting a cronjob and use Download Files
The Drive API allows you to download files that are stored in Google Drive. Also, you can download exported versions of Google Documents (Documents, Spreadsheets, Presentations, etc.) in formats that your app can handle. Drive also supports providing users direct access to a file via the URL in the webViewLink property.
Depending on the type of download you'd like to perform — a file, a Google Document, or a content link — you'll use one of the following URLs:
Download a file — files.get with alt=media file resource
Download and export a Google Doc — files.export
Link a user to a file — webContentLink from the file resource
Sample Code :
$fileId = '0BwwA4oUTeiV1UVNwOHItT0xfa2M';
$content = $driveService->files->get($fileId, array(
'alt' => 'media' ));
Hope this helps and answered all you questions

How to extract the zipped xls file from the email attachment?

I have a module which is supposed to extract the email attachment and place it at a specific location. The code creates the POP3 Client to fetch the mail and has been using EMAIL::MIME::Attachment::Stripper module to extract the attachment as below.
my $mail=$pop->HeadAndBody($i);
my $parsed = Email::MIME->new($mail);
my $stripper = Email::MIME::Attachment::Stripper->new($parsed);
my #attachments = $stripper->attachments;
foreach my $a(#attachments)
{
next if $a->{content_type} !~ /octet-stream/i;
my $f = new IO::File "C:/MAIL_PARSING_DATA/" . "<filename>.<file-extension>", "w" or die "Can not create file!";
print $f $a->{payload};
goto EXITPOINT;
}
The code is working fine for the standard files identified by the Perl module, like spreadsheet etc. But not for the specific mail which has a zipped Excel file as an attachment. While extracting the file the identified content_type by the Perl script for this file is application/octet-stream. While extracting the file using the above-mentioned code the file seems to be broken because:
The file is not getting opened through WinZip, WinRAR or 7-Zip.
File size for the file extracted through this script is slightly different than the same file extracted using Outlook.
Kindly provide some input on the issue.
The problem is here
next if $a->{content_type} !~ /octet-stream/i;
zip have content type as application/zip
#NeoNox, Thanks for the response. But the perl system identifies the file as octet-stream only, not with application/zip.
Anyways, I could find the solution.
I could resolve the problem by writing the file in the binary mode(mentioning explicitely as below:
binmode $fh;
Here the file is being writting in the binary mode So I don't get the output as the broken file.
I am finding the same issue.
XLSX files are not seen as attachments.
I am using IMAP.
It will download the email body, any jpgs or pngs etc but does not find the attached xlsx even when in an email that has attachments that are downloaded.

Resources