WinSendMail.AddAttachmentText
-----------------------------

Adds an attachment to the email based on a text.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [WinSendMail](component_WinSendMail.md) | [7.1](newinversion71.md) | ❌ No | ✅ Yes | ❌ No | ❌ No | ❌ No |

MBS( "WinSendMail.AddAttachmentText"; WinSendMailRef; Value { ; Encoding; FileName } ) 

**MBS**( **"WinSendMail.AddAttachmentText";** /\* Adds an attachment to the email based on a text. \*/  
**$WinSendMailRef**; /\* The email reference number obtained using WinSendMai.CreateEmail function.e.g. $Email \*/   
**$Value**; /\* The text to use for the attachment.e.g. "Hello World" \*/   
**$Encoding**; /\* Optional; The text encoding for text parameter.   
Default is UTF-8.e.g. "UTF8" \*/   
**$FileName**) /\* Optional; The file name to use.  
Default is attachment.txte.g. "test.txt" \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| WinSendMailRef | The email reference number obtained using WinSendMai.CreateEmail function. | $Email |  |
| Value | The text to use for the attachment. | "Hello World" |  |
| Encoding | The text encoding for text parameter.    Default is UTF-8.   Possible encoding names: ANSI, ISO-8859-1, Latin1, Mac, Native, UTF-8, DOS, Hex, Base64 or Windows. More listed in the [FAQ](https://www.monkeybreadsoftware.com/filemaker/faq.shtml). | "UTF8" | Optional |
| FileName | The file name to use.   Default is attachment.txt | "test.txt" | Optional |

### Result

Returns OK or error.

### Description

Adds an attachment to the email based on a text.  
You can use AddAttachment several times to add several attachments.  
  
For Outlook testing shows only one attachment works in older version, while Thunderbird works with several attachments. This may be fixed for Outlook 365.   
Outlook also allows to pass no text and a html file as attachment to build a html email.  
### Examples

Adds an attachment with text field:

 MBS ( "WinSendMail.AddAttachmentText"; $Mail ; MyTable::MyTextField ; "UTF-8" )  
Adds a html attachment:

 MBS ( "WinSendMail.AddAttachmentText"; $Mail ; $html ; "UTF-8"; "test.html" )  
Set HTML for the email:

 Set Variable \[ $EmailID ; Value: MBS ("[WinSendMail.CreateEmail](WinSendMailCreateEmail.md)") \]  
\# prepare HTML from field in FileMaker   
Set Variable \[ $html ; Value: "&lt;html&gt;&lt;body&gt;" &amp; GetAsCSS(EMail::PlainText ) &amp; "&lt;/body&gt;&lt;/html&gt;" \]  
\# replace a placeholder with a value:   
Set Variable \[ $html ; Value: Substitute( $html ; "$$FirstName $$"; MBS ( "[Text.EncodeToHTML](TextEncodeToHTML.md)"; $FirstName ))\]  
\# now pass the html   
Set Variable \[ $r ; Value: MBS ("WinSendMail.AddAttachmentText"; $EmailID ; $html ; "UTF-8"; "test.html") \]  
### See also

- [SendMail.AddAttachmentFile](SendMailAddAttachmentFile.md)
- [SendMail.AddAttachmentText](SendMailAddAttachmentText.md)
- [SendMail.CreateEmail](SendMailCreateEmail.md)
- [Text.EncodeToHTML](TextEncodeToHTML.md)
- [WinSendMail.AddAttachmentContainer](WinSendMailAddAttachmentContainer.md)
- [WinSendMail.AddAttachmentFile](WinSendMailAddAttachmentFile.md)
- [WinSendMail.AttachmentCount](WinSendMailAttachmentCount.md)
- [WinSendMail.CreateEmail](WinSendMailCreateEmail.md)

This function checks for a license.

Created 28th February 2017 , last changed 12nd February 2024

  
[WinSendMail.AddAttachmentFile](WinSendMailAddAttachmentFile.md) - [WinSendMail.AddBCC](WinSendMailAddBCC.md)

[HTML Version](WinSendMailAddAttachmentText.shtml)