EmailParser.Attachment
----------------------

Queries an attachment property.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [EmailParser](component_EmailParser.md) | [5.3](newinversion53.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "EmailParser.Attachment"; EmailID; Index; Selector { ; Extra } ) 

**MBS**( **"EmailParser.Attachment";** /\* Queries an attachment property. \*/  
**$EmailID**; /\* The ID fo the email parser.e.g. $Email \*/   
**$Index**; /\* The index from 0 to [EmailParser.AttachmentCount](EmailParserAttachmentCount.md)-1.e.g. 0 \*/   
**$Selector**; /\* Which value to return. Can be Filename, MimeType, MimeVersion, ContentType, ContentTransferEncoding, ContentDisposition, ContentDescription, contentId, text or container.e.g. "Filename" \*/   
**$Extra**) /\* Optional; For selector = container, you can pass an alternative file name.  
For selector = text, you can pass text encoding here. \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| EmailID | The ID fo the email parser. | $Email |  |
| Index | The index from 0 to [EmailParser.AttachmentCount](EmailParserAttachmentCount.md)-1. | 0 |  |
| Selector | Which value to return. Can be Filename, MimeType, MimeVersion, ContentType, ContentTransferEncoding, ContentDisposition, ContentDescription, contentId, text or container. | "Filename" |  |
| Extra | For selector = container, you can pass an alternative file name.   For selector = text, you can pass text encoding here. |  | Optional |

### Result

Returns value or error.

### Description

Queries an attachment property.  
You can query for example the file name or the mime type.  
For storing in a container, you can query the container property. The attachment is decoded by the plugin.  
  
If you need to directly write to a file, you can use the [EmailParser.WriteAttachment](EmailParserWriteAttachment.md) function.  
You can use [Text.MimeTypeToFileExtension](TextMimeTypeToFileExtension.md) to find the file extension for mime type.  
### Examples

Copy all attachments into records:

 #find all attachments   
Set Variable \[$i ; Value:0\]  
Set Variable \[$c ; Value:MBS ("[EmailParser.AttachmentCount](EmailParserAttachmentCount.md)"; $email )\]  
If \[$c &gt; 0\]  
 Go to Related Record \[Show only related records; From table: “Attachment”; Using layout: “Attachment” (Attachment)\]  
 Go to Layout \[“Attachment” (Attachment)\]  
 Delete All Records \[No dialog\]  
 Loop  
 Set Variable \[$Name ; Value:MBS ("EmailParser.attachment"; $email ; $i ; "filename")\]  
 Set Variable \[$content ; Value:MBS ("EmailParser.attachment"; $email ; $i ; "container")\]  
 New Record/Request  
 Set Field \[Attachment::Content ; $content \]  
 Set Field \[Attachment::FileName ; $name \]  
 Set Field \[Attachment::EmailID ; $EmailRecordID \]  
 Commit Records/Requests \[Skip data entry validation; No dialog\]  
 #next  
 Set Variable \[$i ; Value:$i + 1\]  
 Exit Loop If \[$i = $c \]  
 End Loop  
End If  
### See also

- [EmailParser.AttachmentCount](EmailParserAttachmentCount.md)
- [EmailParser.Parse](EmailParserParse.md)
- [EmailParser.WriteAttachment](EmailParserWriteAttachment.md)
- [Text.MimeTypeToFileExtension](TextMimeTypeToFileExtension.md)

### Release notes

- **Version 13.2**
    - Improved [EmailParser.Attachment](https://www.mbsplugins.eu/EmailParserAttachment.shtml) function to better handle PDF documents and return them as PDF container with preview.
- **Version 9.3**
    - Added parameter for [EmailParser.Inline](http://www.mbsplugins.eu/EmailParserInline.shtml) or [EmailParser.Attachment](http://www.mbsplugins.eu/EmailParserAttachment.shtml) to pass text encoding or file name.

### Example Databases

- [Drag and Drop/DragTest](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Drag%20and%20Drop/DragTest.shtml#7ScriptAnchor_)

### Blog Entries

- [MBS Plugin Advent calendar: 23 - MailParser](https://www.mbsplugins.de/archive/2023-12-23/MBS_Plugin_Advent_calendar_23_/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 13.2pr2](https://www.mbsplugins.de/archive/2023-04-13/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 9.3pr6](https://www.mbsplugins.de/archive/2019-07-17/MBS_FileMaker_Plugin_version_9/monkeybreadsoftware_blog_filemaker)

This function is free to use.

Created 24th September 2015 , last changed 14th July 2019

  
[EmailParser.AttachedEmails](EmailParserAttachedEmails.md) - [EmailParser.AttachmentCount](EmailParserAttachmentCount.md)

[HTML Version](EmailParserAttachment.shtml)