Is it possible to attach a file from firebase storage to an email using the trigger email extension? - firebase-storage

I added the trigger email extension to my firebase project and it works well.
I am now trying to send an email with an attachment from firebase storage.
I tried adding the access token of the file to the content field of the message and the email is sent with the corresponding file (in this case a pdf file) but when I try to open it, it is corrupted.
Am I doing something wrong or is it just not possible to attach files from storage?

it is possible to send an attachment with this extension.
Could you provide an example of how you are adding this attachment? For example:
A link to a file source
Base 64 included content
A link to a file would look like
attachments: [
{
content: "invoice",
filename: "{{invoice_link}}",
},
],
Base 64 content would be similar to:
attachments: [
{ content: "dGhpcyBpcyBhIHRlc3Q=" // base64 string
encoding: "base64"
filename "ImportantDocument.pdf"
}
]

Related

How to Return File from SvelteKit Endpoint

I am trying to serve a PDF file that my SvelteKit app generates and allow a user to download it from an endpoint.
My project structure looks like this:
---------------------
/src/routes/downloads
---------------------
[file].ts
ABC.pdf
XYZ.pdf
My [file].ts endpoint looks like this:
import fs from 'fs'
// ----- GET -----
export async function get({ params }){
//console.log(params.file) -> ABC
var pdf = fs.readFileSync('./src/routes/downloads/'+params.file+'.pdf')
return{
status:200,
headers: {
"Content-type" : "application/pdf",
"Content-Disposition": "attachment; filename="+params.file+".pdf"
},
body: pdf
}
}
So then when I hit http://localhost:3000/downloads/ABC, the PDF file named ABC.pdf downloads.
But my readFileSync path isn't something that's going to work on production. As far as I know, there is no /src/routes folder.
How do I serve my file from a http://localhost:3000 url? Everything I've tried yields a 404 and it can't find the file. I'm also open to a different way of handling this scenario. This is just my best guess of how to do this in SvelteKit.
The recommended way to do this, for adapter-node, is to place your application data in a new folder under your project's root directory (ie. alongside /src and /static). You can then read files with a relative path: fs.readFile('./my-app-data/foo.txt').
For deployment, you just have to make sure to execute node build from the project root, as this guarantees that you have the same working directory during both development and production.
The static folder works, but it is not meant to carry application data—files in this folder represent new routes that are served directly to users, so this is not desirable if your generated files must be protected in any way. Even if they're meant to be public files, it still blurs what is supposed to be production and source data: should a new deploy overwrite all the files in static? If you're not careful, a naming clash could mean overwriting production data.
You can use import.meta.glob for this.
export async function get({ params }){
const file = `./${params.file}.pdf`;
const pdfs = import.meta.glob(('./*.pdf', { as: 'raw' });
const pdf = pdfs[file];
return {
status:200,
headers: {
"Content-type" : "application/pdf",
"Content-Disposition": "attachment; filename="+params.file+".pdf"
},
body: pdf
}
}
The import.meta.glob in combination with the as: 'raw' option will effectively embed the contents of each file in your resulting code. (this is purely server side so no worries about shipping to much to the client)
Note that this of course means that only files present during build can be served this way.
As #Stephane suggest, put your files under statics folder. This way you can serve directly through a reverse proxy, like Nginx

Can I attach files (PDF) to customer.io REST API?

I am trying to send an email through customer.io service and I need to attach a PDF to it. Ive seen little documentation about attachments, so I dont know if it is possible.
I am trying this approach
{
name: 'myCampaign',
data: {
foo: 'bar',
},
attachments: {
'file.pdf': pdfInB64
}
}
As the example here: https://gist.github.com/jrallison/3e43c58cb208841caf11
Thank you !!
It is possible to send PDF's as attachments via customer.io. I think one of your issues is that your attachments object needs to be nested inside of your data object. Ex.
{
"name": "foo_bar",
"data": {
"foo": "bar",
"attachments": {
"helloworld.pdf": "some base64 encoded pdf here"
}
}
}
However, one caveat here is that there's a limit to the size of attachments.
Well, apparently is not possible the way I was thinking about it. For PDF is better to have a link to a host you own
<img src="LINK TO THE DOWNLOAD PDF IMAGE" alt="Download your PDF file">

CQ5 workflow content inbox | Approve folder content wrong url

We have created a workflow to send approval mail to approver. The payload is jcr:content of a folder or a PDF.
After the coding, the behaviour is for:
A pdf : It generate right URL as http:///damadmin.html#/content/ab/cd/abc.pdf
A folder : It generate the wrong url as http:///damadmin.html#/content/folder-name/jcr:content
So, for folder, we have updated the code to change the payload as the folder-path instead of folder-path/jcr:content
for that we used,
WorkflowData wfData = wfSession.newWorkflowData("JCR_PATH", folder_node_path);
wfSession.updateWorkflowData(workItem.getWorkflow(), wfData);
After the code change, When a user modify any dam content like a pdf, the url is correct as http:///damadmin.html#/
but when the user modify a folder properties, the mail sent to approver has the wrong url as http:///
means /damadmin.html# is missing.
We need that the correct link should be added for both PDF and Folder.
Thanks in advance.
Issue is resolved.I am using CQ 5.5.
Sharing my experience.We don't need to change the payload. The payload can remain as jcr:content
We need to do two things:
Make sure the folder-path/jcr:content has the value in property jcr:title. It will be shown in content column of the inbox page.
For the folder link in inbox page, it must be as /content//jcr:content. The problem is because /damadmin.html# is not added before the url.
This problem is not coming for any Asset or Page.
Solution is:
You need add the following code in /libs/cq/workflow/components/inbox/list/json.jsp
A=>
Add private method
private String handleDamPathForFolder(Logger log, String payloadUrl, Session session, WorkItem wi)
{
try
{
if(isFolderNode(session, wi))
{
return ("/damadmin.html#"+payloadUrl);
}
}catch (Exception e)
{
log.error("Unable to handle path creation for work item: " + wi.getId(), e);
}
return payloadUrl;
}
We have to write the method isFolderNode which will return true if the node is a folder.
B=>Replace
JSONWriterUtil.write(writer, "payload", pathBuilder.getPath(wi),JSONWriterUtil.WriteMode.BOTH, xss);
by the follwoing
JSONWriterUtil.write(writer,"payload",handleDamPathForFolder(log,pathBuilder.getPath(wi), session, wi), JSONWriterUtil.WriteMode.BOTH, xss);
<br/>

phpmailer attach pdf from dynamic url

I'm sending an email using phpmailer. I have web service to generate pdf. This pdf is not uploading or downloading to anywhere.
PDF url is like
http://mywebsite/webservices/report/sales_invoice.php?company=development&sale_id=2
I need to attach this dynamic pdf url to my email.
My email sending service url is like
http://mywebsite/webservices/mailservices/sales_email.php
Below is the code which i am using to attach the pdf.
$pdf_url = "../report/sales_invoice.php?company=development&sale_id=2";
$mail->AddAttachment($pdf_url);
Sending message is working but pdf doesn't attached. It gives below message.
Could not access file: ../report/sales_invoice.php?company=development&sale_id=2
I need some help
To have the answer right here:
As phpmailer would not auto-fetch the remote content, you need to do it yourself.
So you go:
// we can use file_get_contents to fetch binary data from a remote location
$url = 'http://mywebsite/webservices/report/sales_invoice.php?company=development&sale_id=2';
$binary_content = file_get_contents($url);
// You should perform a check to see if the content
// was actually fetched. Use the === (strict) operator to
// check $binary_content for false.
if ($binary_content === false) {
throw new Exception("Could not fetch remote content from: '$url'");
}
// $mail must have been created
$mail->AddStringAttachment($binary_content, "sales_invoice.pdf", $encoding = 'base64', $type = 'application/pdf');
// continue building your mail object...
Some other things to watch out for:
Depending on the server response time, your script might run into timing issues. Also, the fetched data might be pretty large and could cause php to exceed its memory allocation.

grails mail: render profile pictures from database in email

in grails-mail plugin you need do define your inline image data in your service, assuming you are using grails mail from a service.
you do this like so in your service.groovy
inline 'header', 'image/jpg', new File('./web-app/images/mailAssets/alert_header_pre.png')
inside your service definition, lets say:
def mailService
def contactUser(userName, email) {
mailService.sendMail {
multipart true
to email
from "marc.heidemann#live.de"
subject "Hello from grails-mail"
text "Hallo from grails-mail multipart text modus"
html view:"/alert/test", model:[name:userName]
inline 'header', 'image/jpg', new File('./web-app/images/mailAssets/alert_header_pre.png')
inline 'footer', 'image/jpg', new File('./web-app/images/mailAssets/suchebottomre.gif')
}
}
for now, the app is rendering the footer and the header image, Ok.
alright, now the plan of the planners of this project is to render profile pictures from database (about 15.000 users) in their emails - can and if then how can this be achieved without declaring every user's profile picture inside the service.groovy? Furthermore those pictures are stored outside of my app at amazon s3. might this be a boundary of mail plugin or is it possible to get this working? What would you offer those planning and creative guys as an alternative if it is not possible to do so? any opinions are welcome.
Loop through your users.
Get the corresponding picture from S3 using the grails-aws-plugin.
Insert picture into email
Send mail using the mail-plugin
That way you don't have to declare it in the service. You can download the pictures from S3 to use them as inline pictures or you could use a url provided by S3.
To access the file for inline usage:
def file = aws.s3().on(bucket).get(name, path)
To get a public url:
def url = aws.s3().on(bucket).url(name, path)