Skip to content

ConvertHTMLAttachmentToPdfAndSend

Description

Creates a PDF from base64 encoded HTML and emails it to the provided recipients.

Syntax

VabletNativeInterface.callNativeMethod(
  "ConvertHTMLAttachmentToPdfAndSend",
  {
    to,
    cc,
    bcc,
    subject,
    body,
    company,
    queueIfNotAbleToSend,
    pdfPageSize,
    attachmentDataBase64Encoded,
    attachmentName,
  },
  (res) => {...}
);

Options

Key Type Description
to
cc
bcc
string
object
array
The to, cc, and bcc fields accept an email, an array of emails, or an array of objects.
Example: [{name:'Name', email:'email@email.com}]
subject string Subject line for the email.
body string The email message. This is placed inside the body of your set email template for vablet.
company string Company name of the email recipient. This is an optional field used for logging and analytics.
queueIfNotAbleToSend boolean If this is set to true the email will attempt to resend until it successfully is sent. Useful for offline emailing.
pdfPageSize object The rendered PDF page size. It is an object with width and height properties.
Example: {'width':pageSizeWidth,'height':pageSizeHeight}
attachmentDataBase64Encoded base64 A base64 encoded string of the HTML to convert into a PDF.
attachmentName string The name of the attached file.

Response

Key Type Description
success boolean Returns true on success and false for any errors.
Always true if queueIfNotAbleToSend is set to true
error string Error message, provided there is one.

Example

VabletNativeInterface.callNativeMethod(
  "ConvertHTMLAttachmentToPdfAndSend",
  {
    to: 'email@email.com',
    cc: ['1@email.com', '2@email.com'],
    bcc: [{name: 'Name 1', email: '1@email.com'},{name: 'Name 2', email: '2@email.com'}],
    subject: 'Sample vablet ConvertHTMLAttachmentToPdfAndSend email',
    body: 'Find attached your converted HTML to PDF document!',
    company: 'Recipient Company',
    queueIfNotAbleToSend: true,
    pdfPageSize: {width: 612, height: 791}, // 'letter' paper size in px
    attachmentDataBase64Encoded: btoa('<h3>Hello World!</h3>'), // convert html to base64
    attachmentName: 'Hello World.pdf',
  },
  (res) => {
    if (res.success) {
      // Success!
      alert('Email sent successfully!')
    } else {
      // Uh oh, let's alert the error!
      alert(res.error)
    }
  }
);