Announcement

Collapse
No announcement yet.

Is there a way to send attached file by email?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is there a way to send attached file by email?

    Hi!
    Is there a way to send file attached to a record by email? (File attached as type "File" only 1 document is attached to that field).
    I need to send it automatically on a workflow execution, thanks

  • #2
    Hi Russ

    You can, either you create a template and attach file to it by default so when sending email the file will be attached by default (this is static means the file attached to the template is constant). If it was me i would prefer to use something dynamic so instead of using send email task i would rather use Script Task and build a formula like below to send the email.

    Below is an example of how to send a contact an email with attached document (related document).

    Code:
    // Find first document related to this contact
    $documentId = record\findRelatedOne('Contact', id, 'documents', 'createdAt', 'desc');
    
    $documentName = record\attribute('Document', $documentId, 'name');
    
    $fileId = record\attribute('Document', $documentId, 'fileId');
    
    // Create the attachment 
    $attachmentId = record\create('Attachment',
    'role', 'Attachment',
    'type', record\attribute('Attachment', $fileId, 'type'),
    'size', record\attribute('Attachment', $fileId, 'size'),
    'global', record\attribute('Attachment', $fileId, 'global'),
    'name', record\attribute('Attachment', $fileId, 'name'),
    'sourceId', $fileId,
    'storage', record\attribute('Attachment', $fileId, 'storage')
    );
    
    // Build email body
    $emailBody = string\concatenate(
    'Please find attached document: ', $documentName, '<br> Cheers');
    
    // Create the email
    $emailId = record\create(
    'Email',
    'to', entity\attribute('emailAddress'),
    'subject', 'Required Document',
    'body', $emailBody,
    'isHtml', true,
    'status', 'Sending',
    'attachmentsIds', list($attachmentId),
    'parentId', id,
    'parentType', 'Contact'
    );
    
    // Send the email
    ext\email\send($emailId);
    ​
    Hope this helps.
    Rabii
    Web Dev

    Comment


    • #3
      Originally posted by rabii View Post
      Hi Russ

      You can, either you create a template and attach file to it by default so when sending email the file will be attached by default (this is static means the file attached to the template is constant). If it was me i would prefer to use something dynamic so instead of using send email task i would rather use Script Task and build a formula like below to send the email.

      Below is an example of how to send a contact an email with attached document (related document).

      Code:
      // Find first document related to this contact
      $documentId = record\findRelatedOne('Contact', id, 'documents', 'createdAt', 'desc');
      
      $documentName = record\attribute('Document', $documentId, 'name');
      
      $fileId = record\attribute('Document', $documentId, 'fileId');
      
      // Create the attachment
      $attachmentId = record\create('Attachment',
      'role', 'Attachment',
      'type', record\attribute('Attachment', $fileId, 'type'),
      'size', record\attribute('Attachment', $fileId, 'size'),
      'global', record\attribute('Attachment', $fileId, 'global'),
      'name', record\attribute('Attachment', $fileId, 'name'),
      'sourceId', $fileId,
      'storage', record\attribute('Attachment', $fileId, 'storage')
      );
      
      // Build email body
      $emailBody = string\concatenate(
      'Please find attached document: ', $documentName, '<br> Cheers');
      
      // Create the email
      $emailId = record\create(
      'Email',
      'to', entity\attribute('emailAddress'),
      'subject', 'Required Document',
      'body', $emailBody,
      'isHtml', true,
      'status', 'Sending',
      'attachmentsIds', list($attachmentId),
      'parentId', id,
      'parentType', 'Contact'
      );
      
      // Send the email
      ext\email\send($emailId);
      ​
      Hope this helps.
      Thanks, helped!

      Comment

      Working...
      X