Closed atanaskanchev closed 2 years ago
Hi @atanaskanchev.
Could you possibly be missing a content type definition?
export interface Attachment {
filename?: string;
content?: string;
path?: string;
encoding?: string;
raw?: string;
href?: string;
httpHeaders?: any;
contentDisposition?: string;
contentType?: string;
headers?: any;
cid?: string;
}
Hi @atanaskanchev.
Could you possibly be missing a content type definition?
export interface Attachment { filename?: string; content?: string; path?: string; encoding?: string; raw?: string; href?: string; httpHeaders?: any; contentDisposition?: string; contentType?: string; headers?: any; cid?: string; }
Hi @dackers86 the contentType is set to application/pdf
I've just notice some strange warning in the execution logs:
{"location":"us-central1","mailCollection":"mail","smtpConnectionUri":"<omitted>","smtpPassword":"<omitted>","defaultFrom":"xxx","defaultReplyTo":"xxx","usersCollection":"users","templatesCollection":"mail_templates","testing":false,"severity":"INFO","message":"Started execution of extension with configuration"} {"severity":"INFO","message":"Completed execution of extension"}
{"severity":"WARNING","message":"message 'undefined' is not a valid object - please add as an object or firestore map, otherwise you may experience unexpected results."}
That warning message should be ok as it is just stating a message object has not been included.
This may be an edge case, but the attachments are expected to be included in the template that you have included as part of your document.
This should be accessed through a name
and any relevant data
. For example:
template?: {
name: string;
data?: { [key: string]: any };
};
``
The template looks like
and it is set in the mail doc as
@atanaskanchev
Below is a basic example of how to add a base64 attachment through a template:
/** create an example template */
await firestore()
.collection("templates")
.doc("base64_example")
.set({
html: "testing",
subject: "testing subject",
attachments: [
{
filename: `ImportantDocument.pdf`,
content: "THISISAB64STRING",
encoding: "base64",
},
],
});
/** send an email using the new template*/
await firestore()
.collection("mails")
.add({
to: ["darren@invertase.io"],
template: {
name: "base64_example",
data: {},
},
});
Is this the type of solution you are looking for?
Hi @dackers86 thanks for the suggestion, but my goal is to use the template doc to set the html body and dynamically generate one or more base64 attachments. Adding the attachments to the template doc defeats its purpose as a template. I suppose can generate a new template per email, but ideally the template should not handle the attachments
@atanaskanchev I think I understand, does this example meet your requirements?
await firestore().collection("templates").doc("base64_example").set({
html: "{{html_data}}",
subject: "{{subject_data}}",
});
await firestore()
.collection("mail")
.add({
to: ["darren@invertase.io"],
message: {
attachments: [
{
filename: `ImportantDocument.pdf`,
content: "",
encoding: "base64",
},
],
},
template: {
name: "base64_example",
data: { html_data: "This is html", subject_data: "This is a subject" },
},
});
@dackers86 this works perfectly, thanks for your help!
This should really be in the documentation, it was driving me crazy until I found this issue.
[READ] Step 1: Are you in the right place?
Issues filed here should be about bugs for a specific extension in this repository. If you have a general question, need help debugging, or fall into some other category use one of these other channels:
[REQUIRED] Step 2: Describe your configuration
firestore-send-email
0.1.17
[REQUIRED] Step 3: Describe the problem
The extension does not process a base64 encoded attachment. The email is successfully send, however, the email does not have a file attachment.
Steps to reproduce:
Create a record in the
mail
collectionExpected result
The email should have a PDF attachment.
Actual result
There is no attachment in the received email.