Email attachments
Learn how to test the email attachments with SMSByrd.
Before you begin
The examples shown below are based on two key assumptions:
- That you have already create a basic automated test using our getting started guides.
- You have a chosen assertion library that you will use to test the values shown below.
How many attachments
The attachments property of a message contains an array of attachments. The length of this array corresponds to the number of files attached to the email.
//code snippet
Testing the file name and content type
A hashtag icon Each attachment contains metadata on the file name and content type.
//code snippet
Testing attachment file size
The length property returns the size of the attached file (in bytes).
Embedded Images
If an email contains embedded images then the contentId attribute will be populated and will have a corresponding entry in the images array.
Fetching an attachment as base64
You can fetch the content of an attachment, encoded as base64, using the “get attachment” method:
//code snippet
Saving an attachment to disk
You can also write an attached file to disk:
//code snippet