SendMail.AddAttachmentFile
--------------------------

Adds an attachment to the email based on a file path.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [SendMail](component_SendMail.md) | [4.3](newinversion43.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "SendMail.AddAttachmentFile"; EmailID; Path { ; Name; MimeType; InlineID; Method } ) 

**MBS**( **"SendMail.AddAttachmentFile";** /\* Adds an attachment to the email based on a file path. \*/  
**$EmailID**; /\* The email reference number obtained using [SendMail.CreateEmail](SendMailCreateEmail.md) function. \*/   
**$Path**; /\* The native file path to the file to include as attachment.e.g. "/Users/cs/Desktop/sample.pdf" \*/   
**$Name**; /\* Optional; The name for the attachment.  
If empty, version 6.2 or newer uses file name from file path.e.g. "sample.pdf" \*/   
**$MimeType**; /\* Optional; The mime type to use. e.g. "application/pdf" for PDF files. If missing, we use "application/octet-stream".  
Version 6.2 or newer detects mime type from file extension if needed.e.g. "application/octet-stream" \*/   
**$InlineID**; /\* Optional; The content ID for inline images (CID).  
Empty text or no parameter gives regular attachment.  
  
You define this yourself. Can be just a file name or some uuid, which is then referenced in html with "cid:" prefix in the img src attribute.e.g. "test.png@3C111B0E.81ED.478A.912C.4B64F538003C" \*/   
**$Method**) /\* Optional; The method for the content-type parameter.  
Currently only for sending calendar invitiations.e.g. "REQUEST" \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| EmailID | The email reference number obtained using [SendMail.CreateEmail](SendMailCreateEmail.md) function. | $EmailID |  |
| Path | The native file path to the file to include as attachment. | "/Users/cs/Desktop/sample.pdf" |  |
| Name | The name for the attachment.   If empty, version 6.2 or newer uses file name from file path. | "sample.pdf" | Optional |
| MimeType | The mime type to use. e.g. "application/pdf" for PDF files. If missing, we use "application/octet-stream".   Version 6.2 or newer detects mime type from file extension if needed. | "application/octet-stream" | Optional |
| InlineID | The content ID for inline images (CID).   Empty text or no parameter gives regular attachment.      You define this yourself. Can be just a file name or some uuid, which is then referenced in html with "cid:" prefix in the img src attribute. | "test.png@3C111B0E.81ED.478A.912C.4B64F538003C" | Optional |
| Method | The method for the content-type parameter.   Currently only for sending calendar invitiations. | "REQUEST" | Optional |

### Result

Returns OK or error.

### Description

Adds an attachment to the email based on a file path.  
Attachments over 100 MB are not supported.  
Version 5 of MBS Plugin can encode file name for preserving non ASCII characters. Still for compatibility it is recommended to use simply ASCII names.  
You can use [Text.FileExtensionToMimeType](TextFileExtensionToMimeType.md) to find the mime type for a file extension.  
You can use AddAttachment several times to add several attachments.  
  
This function requires a native path. Use [Path.FileMakerPathToNativePath](PathFileMakerPathToNativePath.md) to convert a FileMaker path to a native path if required. If you like to have the user choose the path, you can use [FileDialog](component_FileDialog.md) functions.  
For Server be aware that server has limited permissions and may not be able to access all files on a computer.  
### Examples

Add attachment:

 Set Variable \[$r ; Value:MBS ("SendMail.AddAttachmentFile"; $EmailID ; Attachment::Path ; Attachment::Name ; Attachment::Type )\]  
Recursive custom function to add a list of files:

 MBSAttachment(EmailID, FilePathList, Flag\_inline)  
  
// e.g. $r =MBSattachment ( $EmailID ; MyTable::FilePathList ; 1 ) ;  
  
Case(  
ValueCount (FilePathList ) &gt; 0;  
 Let(  
 \[  
 §element =   
 ValueCount (FilePathList ) ;  
 §Line =   
 GetValue( FilePathList; §element );  
 §InlineID=   
 MBS ( "[Path.LastPathComponent](PathLastPathComponent.md)"; §line ) ;  
 §r=   
 MBS (   
 "SendMail.AddAttachmentFile";   
 EmailID;  
 §Line;  
 ""; /\* file name from path automatically \*/  
 ""; /\* mime name from file name automatically \*/  
 Case(  
 Flag\_inline = 1;  
 §InlineID ;  
 ""  
 )  
 )  
 \];  
  
 // call recursive for next file:  
 MBSattachment(  
 EmailID;   
 Trim(  
 Substitute(   
 "¶" &amp; FilePathList;   
 "¶" &amp; §Line ;   
 ""   
 ));   
 Flag\_inline  
 )  
);  
 ""  
)  
### See also

- [Path.FileMakerPathToNativePath](PathFileMakerPathToNativePath.md)
- [Path.LastPathComponent](PathLastPathComponent.md)
- [SendMail.AddAttachmentContainer](SendMailAddAttachmentContainer.md)
- [SendMail.AddAttachmentText](SendMailAddAttachmentText.md)
- [SendMail.CreateEmail](SendMailCreateEmail.md)
- [SendMail.PrepareCURL](SendMailPrepareCURL.md)
- [Text.FileExtensionToMimeType](TextFileExtensionToMimeType.md)
- [WinSendMail.AddAttachmentContainer](WinSendMailAddAttachmentContainer.md)
- [WinSendMail.AddAttachmentFile](WinSendMailAddAttachmentFile.md)
- [WinSendMail.AddAttachmentText](WinSendMailAddAttachmentText.md)

### Release notes

- **Version 11.2**
    - Added optional ContentTypeMethod parameter for [SendMail.AddAttachmentContainer](https://www.mbsplugins.eu/SendMailAddAttachmentContainer.shtml), [SendMail.AddAttachmentFile](https://www.mbsplugins.eu/SendMailAddAttachmentFile.shtml) and [SendMail.AddAttachmentText](https://www.mbsplugins.eu/SendMailAddAttachmentText.shtml) functions.

### Example Databases

- [CURL/Email/Batch Emailer](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/Email/Batch%20Emailer.shtml#1ScriptAnchor_)
- [CURL/Email/Build and send Email](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/Email/Build%20and%20send%20Email.shtml#1ScriptAnchor_)
- [CURL/Email/Build and send HTML Email with inline graphics](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/Email/Build%20and%20send%20HTML%20Email%20with%20inline%20graphics.shtml#1ScriptAnchor_)

### Blog Entries

- [Sending email with a huge custom function](https://www.mbsplugins.de/archive/2021-06-26/Sending_email_with_a_huge_cust/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 11.2pr1](https://www.mbsplugins.de/archive/2021-04-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [Sending emails in FileMaker with MBS Plugin](https://www.mbsplugins.de/archive/2016-10-03/Sending_emails_in_FileMaker_wi/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 6.2pr1](https://www.mbsplugins.de/archive/2016-03-19/MBS_FileMaker_Plugin_version_6/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 5.1pr1](https://www.mbsplugins.de/archive/2015-03-16/MBS_FileMaker_Plugin_version_5/monkeybreadsoftware_blog_filemaker)
- [Sending Email with FileMaker via MBS Plugin](https://www.mbsplugins.de/archive/2014-09-29/Sending_Email_with_FileMaker_v/monkeybreadsoftware_blog_filemaker)

### FileMaker Magazin

- [Ausgabe 5/2014, Seite 26](https://filemaker-magazin.de/neuigkeit/3759-Appetithappen-FMM_201405)

This function checks for a license.

Created 3th September 2014 , last changed 13th February 2024

  
[SendMail.AddAttachmentContainer](SendMailAddAttachmentContainer.md) - [SendMail.AddAttachmentText](SendMailAddAttachmentText.md)

[HTML Version](SendMailAddAttachmentFile.shtml)