Layer7 API Management

Expand all | Collapse all

Sending Email Assertion with Attachment

Jump to Best Answer
  • 1.  Sending Email Assertion with Attachment

    Broadcom Employee
    Posted 17 days ago
    We got a json payload with multiple attachment in base 64 format

    "messages": [ {
    "channel": "email",
    "destination": [""],
    "message": {
    "content": "samplebase64encoded content",
    "subject": "Sample subject",
    "content": "base64encodedFile",
    "name": "Test",
    "sha256Hash": "f454d98fc28822193d9b486ce52aa8ddde68db088c49e31359d49150b22b9677"


    The attachment can be multiple any suggestion on how to add
    all the attachment as we cannot know the number of attachments

    Pre-Sales Consultant
    CA Southern Africa

  • 2.  RE: Sending Email Assertion with Attachment
    Best Answer

    Posted 14 days ago
    Hello Ronald,

    We had run into same problem recently and I was able to find a way to get this working.

    You need to build a MIME message with multiple attachments and then feed it to "send email assertion"

    Below are the steps.

    1. Evaluate the json path expression to get the attachment array from the request.

    2. Add run assertion for each item to iterate through each attachment.

    3. Inside the loop construct the MIME message like below

    Each iteration will build this MIME message

    4. Close the MIME message using another set context variable assertion as below

    5. Feed the final variable to the send email assertion

    This will send the multiple attachments via email.

    Please let me know if you need any further details.


  • 3.  RE: Sending Email Assertion with Attachment

    Posted 10 days ago

    I have an issue with looping trough an rest with base64 encoded REST with attachments.

    My issue is not constructing the MIME message but the format of the attachment. The attachment gets sent but the file is corrupt.

    I tried do base64 decoding into string, into attachment of different content types. Even tried different encoding types e.g. UTF-8 and Windows-1252.

    Even tried forcing the content type to what I send in via REST

    API Tech Lead

  • 4.  RE: Sending Email Assertion with Attachment

    Posted 9 days ago

    I figured this out.

    By setting the Content-Transfer-Encoding: base64 you can use the base64 encoded string as is and not try and decode it.

    Content-Description: File Attachment
    Content-Disposition: attachment;filename="${attachmentName.result}"
    Content-Type: ${attachmentContentType.result}
    Content-Transfer-Encoding: base64

    Using octet-stream also works

    Content-Type: application/octet-stream

    If you need to do document type filtering you can actually extract the content type from the file

    Note the character encoding when you decode

    Convert the content to hex

    Then just capture a few packets from the start of the file

    You can now use those headers to validate the file type. e.g.

    API Tech Lead