Documentation Guides
Save, load and export
Save email JSON in your application, reopen it and export HTML for delivery.
On this page
Choose where to save
To manage emails in your own backend, disable hosted autosave and save the complete document from onDocumentChange. To keep drafts and version history in Weavour instead, use hosted drafts.
Save the complete document
Persist schemaVersion, content, subject and preheader together. onChange contains only raw content; use onDocumentChange to keep the complete email.
The example sends the latest document when the user chooses Save. Implement /api/email-document in your application with authentication and access checks. Show success only after the request succeeds.
import { mount } from '@weavour/editor';
let latestEmail: unknown;
const editor = mount('#email-editor', {
editorKey: 'YOUR_PUBLIC_EDITOR_KEY',
userId: 'user-123',
enableAutosave: false,
onDocumentChange(email) {
latestEmail = email;
},
onError: console.error,
});
// Call from your Save action. Your backend authenticates the host user.
async function saveEmail() {
await editor.ready;
if (!latestEmail) throw new Error('The document is not available yet.');
const response = await fetch('/api/email-document', {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(latestEmail),
});
if (!response.ok) throw new Error('The email could not be saved.');
}Reopen a saved email
Pass the saved envelope as emailDocument. Do not combine it with document, subject, preheader or draftId. To load another email, save current work and mount a new instance.
import { mount, type EmailDocument } from '@weavour/editor';
// Retrieve this envelope from your authenticated application backend.
async function openSavedEmail(savedEmail: EmailDocument) {
const editor = mount('#email-editor', {
editorKey: 'YOUR_PUBLIC_EDITOR_KEY',
userId: 'user-123',
emailDocument: savedEmail,
enableAutosave: false,
onError: console.error,
});
await editor.ready;
return editor;
}Export HTML and plain text
After editor.ready, call exportHTML(). Use html, text, subject and preheader in your delivery workflow. Exporting does not save the document. previewHtml is a display snapshot, not the final email.
Exports retain placeholder tokens and condition syntax. Check mergeTagIssues and displayConditionIssues, then resolve personalization before sending.
// Run from your Export or Send action; show failures in your UI.
try {
await editor.ready;
const output = await editor.exportHTML();
console.log(output.html, output.text, output.subject, output.preheader);
// Resolve merge tags and conditions before submitting to your provider.
} catch (error) {
console.error('Export failed:', error);
}