# mail

(plugins.mail)

## Overview

The `mail` plugin enables sending and receiving emails, with additional support for attachments, email validation, and property configuration. It supports creating binary and text-based attachments, specifying MIME types, and handling exceptions that occur during mail operations. The plugin can process incoming mail from POP3 accounts, with options for leaving messages on the server, retrieving headers, and filtering by sent date.

Emails can be sent individually or in bulk. Bulk emails are optimized to prevent responses such as "out of office" messages. The plugin supports HTML-formatted messages, multiple recipients, and optional CC/BCC configurations. Additional customization is available through SMTP host settings and override properties. Attachments can be added as single files or arrays, providing flexibility for diverse email content. Utility methods like email address validation and plain address extraction are also available.

## Properties

| Property                                    | Description                                                                                                                                                                                                   |
| ------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `mail.mime.charset`                         | Specify the name of the charset to use for mail encoding (leave emtpy for system default), see <http://java.sun.com/j2se/1.4.2/docs/api/java/nio/charset/Charset.html> forinfo which charset names are usable |
| `mail.from`                                 | Default 'from' address if none is specified                                                                                                                                                                   |
| `mail.smtp.username`                        | Specify username if using authentication                                                                                                                                                                      |
| `mail.smtp.port`                            | The port of SMTP server to deliver the mails to                                                                                                                                                               |
| `mail.smtp.password`                        | Specify password if using authentication                                                                                                                                                                      |
| `mail.smtp.auth`                            | Use authentication (true/false), defaults to false.                                                                                                                                                           |
| `mail.smtp.starttls.enable`                 | Use START/TLS (true/false), defaults to false .                                                                                                                                                               |
| `mail.smtp.host`                            | The name of SMTP server to deliver the mails to                                                                                                                                                               |
| `mail.smtp.connectiontimeout`               | Socket connection timeout value in milliseconds. Default is infinite timeout.                                                                                                                                 |
| `mail.smtp.ssl.enable`                      | Use SSL (true/false), defaults to false .                                                                                                                                                                     |
| `mail.development.override.address`         | Specify an email address to which all email will be send instead of the specified To, Cc and Bcc addresses.The specified to, Cc and Bcc addresses will be added to the Subject.                               |
| `mail.pop3.host`                            | The name of POP3 server to recieve mails from                                                                                                                                                                 |
| `mail.server.allowUnauthenticatedRMIAccess` | Allow mailserver access for unauthenticated smart (rmi) client (true/false), defaults to false                                                                                                                |
| `mail.pop3.apop.enable`                     | Whether or not to use APOP for authentication (true/false), defaults to false.                                                                                                                                |
| `mail.smtp.timeout`                         | Socket I/O timeout value in milliseconds. Default is infinite timeout.                                                                                                                                        |

## **Returned Types**

[MailMessage](https://docs.servoy.com/reference/servoyextensions/server-plugins/mail/mailmessage),[Attachment](https://docs.servoy.com/reference/servoyextensions/server-plugins/mail/attachment),

## Properties Summarized

| Type                                                                         | Name          | Summary                        |
| ---------------------------------------------------------------------------- | ------------- | ------------------------------ |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) | [from](#from) | Returns the value of the mail. |

## Methods Summarized

| Type                                                                                              | Name                                                                                                                                                                                                          | Summary                                                                                                                              |
| ------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| [Attachment](https://docs.servoy.com/reference/servoyextensions/server-plugins/mail/attachment)   | [createBinaryAttachment(filename, binarydata)](#createbinaryattachment-filename-binarydata)                                                                                                                   | Creates a binary attachment object.                                                                                                  |
| [Attachment](https://docs.servoy.com/reference/servoyextensions/server-plugins/mail/attachment)   | [createBinaryAttachment(filename, binarydata, mimeType)](#createbinaryattachment-filename-binarydata-mimetype)                                                                                                | Creates a binary attachment object.                                                                                                  |
| [Attachment](https://docs.servoy.com/reference/servoyextensions/server-plugins/mail/attachment)   | [createTextAttachment(filename, textdata)](#createtextattachment-filename-textdata)                                                                                                                           | Creates a text based attachment objec with the default 'text/plain' mimetype                                                         |
| [Attachment](https://docs.servoy.com/reference/servoyextensions/server-plugins/mail/attachment)   | [createTextAttachment(filename, textdata, mimeType)](#createtextattachment-filename-textdata-mimetype)                                                                                                        | Creates a text based attachment object.                                                                                              |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)                      | [getLastSendMailExceptionMsg()](#getlastsendmailexceptionmsg)                                                                                                                                                 | Get the exception that occurred in the last sendMail attempt (null if no exception occurred).                                        |
| [MailMessage](https://docs.servoy.com/reference/servoyextensions/server-plugins/mail/mailmessage) | [getMailMessage(binaryblob/string)](#getmailmessage-binaryblob/string)                                                                                                                                        | Helper method, returns MailMessage object from binary or 7bits string.                                                               |
| [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array)                        | [getPlainMailAddresses(addressesString)](#getplainmailaddresses-addressesstring)                                                                                                                              | Helper method to only get the plain addresses.                                                                                       |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)                    | [isValidEmailAddress(email)](#isvalidemailaddress-email)                                                                                                                                                      | Checks whether the given e-mail address is valid or not.                                                                             |
| [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array)                        | [receiveMail(username, password, leaveMsgsOnServer)](#receivemail-username-password-leavemsgsonserver)                                                                                                        | Receive mails from pop3 account.                                                                                                     |
| [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array)                        | [receiveMail(username, password, leaveMsgsOnServer, receiveMode)](#receivemail-username-password-leavemsgsonserver-receivemode)                                                                               | Receive mails from pop3 account.                                                                                                     |
| [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array)                        | [receiveMail(username, password, leaveMsgsOnServer, receiveMode, onlyReceiveMsgWithSentDate)](#receivemail-username-password-leavemsgsonserver-receivemode-onlyreceivemsgwithsentdate)                        | Receive mails from pop3 account.                                                                                                     |
| [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array)                        | [receiveMail(username, password, leaveMsgsOnServer, receiveMode, onlyReceiveMsgWithSentDate, pop3Host)](#receivemail-username-password-leavemsgsonserver-receivemode-onlyreceivemsgwithsentdate-pop3host)     | Receive mails from pop3 account.                                                                                                     |
| [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array)                        | [receiveMail(username, password, leaveMsgsOnServer, receiveMode, onlyReceiveMsgWithSentDate, properties)](#receivemail-username-password-leavemsgsonserver-receivemode-onlyreceivemsgwithsentdate-properties) | Receive mails from pop3 account.                                                                                                     |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)                    | [sendBulkMail(to, from, subject, msgText)](#sendbulkmail-to-from-subject-msgtext)                                                                                                                             | Send a bulk mail, if you make the msgText start with \<html> the message will be sent in html (and you can use all html formatting). |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)                    | [sendBulkMail(to, from, subject, msgText, cc)](#sendbulkmail-to-from-subject-msgtext-cc)                                                                                                                      | Send a bulk mail, if you make the msgText start with \<html> the message will be sent in html (and you can use all html formatting). |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)                    | [sendBulkMail(to, from, subject, msgText, cc, bcc)](#sendbulkmail-to-from-subject-msgtext-cc-bcc)                                                                                                             | Send a bulk mail, if you make the msgText start with \<html> the message will be sent in html (and you can use all html formatting). |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)                    | [sendBulkMail(to, from, subject, msgText, cc, bcc, attachment)](#sendbulkmail-to-from-subject-msgtext-cc-bcc-attachment)                                                                                      | Send a bulk mail, if you make the msgText start with \<html> the message will be sent in html (and you can use all html formatting). |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)                    | [sendBulkMail(to, from, subject, msgText, cc, bcc, attachment, smtpHost)](#sendbulkmail-to-from-subject-msgtext-cc-bcc-attachment-smtphost)                                                                   | Send a bulk mail, if you make the msgText start with \<html> the message will be sent in html (and you can use all html formatting). |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)                    | [sendBulkMail(to, from, subject, msgText, cc, bcc, attachment, overrideProperties)](#sendbulkmail-to-from-subject-msgtext-cc-bcc-attachment-overrideproperties)                                               | Send a bulk mail, if you make the msgText start with \<html> the message will be sent in html (and you can use all html formatting). |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)                    | [sendBulkMail(to, from, subject, msgText, cc, bcc, attachments)](#sendbulkmail-to-from-subject-msgtext-cc-bcc-attachments)                                                                                    | Send a bulk mail, if you make the msgText start with \<html> the message will be sent in html (and you can use all html formatting). |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)                    | [sendBulkMail(to, from, subject, msgText, cc, bcc, attachments, smtpHost)](#sendbulkmail-to-from-subject-msgtext-cc-bcc-attachments-smtphost)                                                                 | Send a bulk mail, if you make the msgText start with \<html> the message will be sent in html (and you can use all html formatting). |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)                    | [sendBulkMail(to, from, subject, msgText, cc, bcc, attachments, overrideProperties)](#sendbulkmail-to-from-subject-msgtext-cc-bcc-attachments-overrideproperties)                                             | Send a bulk mail, if you make the msgText start with \<html> the message will be sent in html (and you can use all html formatting). |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)                    | [sendMail(to, from, subject, msgText)](#sendmail-to-from-subject-msgtext)                                                                                                                                     | Send a mail, if you make the msgText start with \<html> the message will be sent in html (and you can use all html formatting).      |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)                    | [sendMail(to, from, subject, msgText, cc)](#sendmail-to-from-subject-msgtext-cc)                                                                                                                              | Send a mail, if you make the msgText start with \<html> the message will be sent in html (and you can use all html formatting).      |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)                    | [sendMail(to, from, subject, msgText, cc, bcc)](#sendmail-to-from-subject-msgtext-cc-bcc)                                                                                                                     | Send a mail, if you make the msgText start with \<html> the message will be sent in html (and you can use all html formatting).      |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)                    | [sendMail(to, from, subject, msgText, cc, bcc, attachment)](#sendmail-to-from-subject-msgtext-cc-bcc-attachment)                                                                                              | Send a mail, if you make the msgText start with \<html> the message will be sent in html (and you can use all html formatting).      |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)                    | [sendMail(to, from, subject, msgText, cc, bcc, attachment, smtpHost)](#sendmail-to-from-subject-msgtext-cc-bcc-attachment-smtphost)                                                                           | Send a mail, if you make the msgText start with \<html> the message will be sent in html (and you can use all html formatting).      |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)                    | [sendMail(to, from, subject, msgText, cc, bcc, attachment, overrideProperties)](#sendmail-to-from-subject-msgtext-cc-bcc-attachment-overrideproperties)                                                       | Send a mail, if you make the msgText start with \<html> the message will be sent in html (and you can use all html formatting).      |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)                    | [sendMail(to, from, subject, msgText, cc, bcc, attachments)](#sendmail-to-from-subject-msgtext-cc-bcc-attachments)                                                                                            | Send a mail, if you make the msgText start with \<html> the message will be sent in html (and you can use all html formatting).      |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)                    | [sendMail(to, from, subject, msgText, cc, bcc, attachments, smtpHost)](#sendmail-to-from-subject-msgtext-cc-bcc-attachments-smtphost)                                                                         | Send a mail, if you make the msgText start with \<html> the message will be sent in html (and you can use all html formatting).      |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)                    | [sendMail(to, from, subject, msgText, cc, bcc, attachments, overrideProperties)](#sendmail-to-from-subject-msgtext-cc-bcc-attachments-overrideproperties)                                                     | Send a mail, if you make the msgText start with \<html> the message will be sent in html (and you can use all html formatting).      |

## Properties Detailed

### from

Returns the value of the mail.from property which is set on the admin page.

**Type**\
[String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)

**Sample**

```js
var from = plugins.mail.from
```

## Methods Detailed

### createBinaryAttachment(filename, binarydata)

Creates a binary attachment object.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **filename** ;
* [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) **binarydata** ;

**Returns:** [Attachment](https://docs.servoy.com/reference/servoyextensions/server-plugins/mail/attachment) an Attachment object created with the specified filename and binary data, or null if the inputs are invalid.

**Sample**

```js
var attachment1 = plugins.mail.createBinaryAttachment('logo1.gif',plugins.file.readFile('c:/temp/a_logo.gif'));
var attachment2 = plugins.mail.createBinaryAttachment('logo2.gif',plugins.file.readFile('c:/temp/another_logo.gif'));
var success = plugins.mail.sendMail('to_someone@example.com', 'John Cobb <from_me@example.org>', 'subject', 'msgText',null,null,new Array(attachment1,attachment2));
if (!success)
{
	plugins.dialogs.showWarningDialog('Alert','Failed to send mail','OK');
}
```

### createBinaryAttachment(filename, binarydata, mimeType)

Creates a binary attachment object.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **filename** ;
* [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) **binarydata** ;
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **mimeType** ;

**Returns:** [Attachment](https://docs.servoy.com/reference/servoyextensions/server-plugins/mail/attachment) an Attachment object created with the specified filename, binary data, and MIME type, or null if the inputs are invalid.

**Sample**

```js
var attachment1 = plugins.mail.createBinaryAttachment('logo1.gif',plugins.file.readFile('c:/temp/a_logo.gif', 'image/gif'));
var attachment2 = plugins.mail.createBinaryAttachment('logo2.gif',plugins.file.readFile('c:/temp/another_logo.gif', 'image/gif'));
var success = plugins.mail.sendMail('to_someone@example.com', 'John Cobb <from_me@example.org>', 'subject', 'msgText',null,null,new Array(attachment1,attachment2));
if (!success)
{
	plugins.dialogs.showWarningDialog('Alert','Failed to send mail','OK');
}
```

### createTextAttachment(filename, textdata)

Creates a text based attachment objec with the default 'text/plain' mimetype

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **filename** ;
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **textdata** ;

**Returns:** [Attachment](https://docs.servoy.com/reference/servoyextensions/server-plugins/mail/attachment) an Attachment object created with the specified filename and text data, using the default MIME type of ‘text/plain’, or null if the inputs are invalid.

**Sample**

```js
var attachment = plugins.mail.createTextAttachment('readme.html','<html>bla bla bla');
var success = plugins.mail.sendMail('to_someone@example.com', 'John Cobb <from_me@example.com>', 'subject', 'msgText',null,null,attachment);
if (!success)
{
	plugins.dialogs.showWarningDialog('Alert','Failed to send mail','OK');
}
```

### createTextAttachment(filename, textdata, mimeType)

Creates a text based attachment object.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **filename** ;
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **textdata** ;
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **mimeType** ;

**Returns:** [Attachment](https://docs.servoy.com/reference/servoyextensions/server-plugins/mail/attachment) an Attachment object created with the specified filename, text data, and MIME type, or null if the inputs are invalid.

**Sample**

```js
var attachment = plugins.mail.createTextAttachment('readme.html','<html>bla bla bla', 'text/html');
var success = plugins.mail.sendMail('to_someone@example.com', 'John Cobb <from_me@example.com>', 'subject', 'msgText',null,null,attachment);
if (!success)
{
	plugins.dialogs.showWarningDialog('Alert','Failed to send mail','OK');
}
```

### getLastSendMailExceptionMsg()

Get the exception that occurred in the last sendMail attempt (null if no exception occurred).

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) The exception message from the last sendMail attempt, or null if no exception occurred.

**Sample**

```js
var success = plugins.mail.sendMail('to_someone@example.com,to_someone_else@example.org', 'John Cobb <from_me@example.com>', 'subject', 'my message',null,'unnamed@example.com');
if (!success)
{
	plugins.dialogs.showWarningDialog('Alert',plugins.mail.getLastSendMailExceptionMsg(),'OK');
}
```

### getMailMessage(binaryblob/string)

Helper method, returns MailMessage object from binary or 7bits string.

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **binaryblob/string** ;

**Returns:** [MailMessage](https://docs.servoy.com/reference/servoyextensions/server-plugins/mail/mailmessage) a MailMessage object created from the provided binary or string data, or null if an error occurred.

**Sample**

```js
var msg = plugins.mail.getMailMessage(myBlob);
if (msg != null) //if is null error occurred!
{
	application.output(msg.getFromAddresses())
}
```

### getPlainMailAddresses(addressesString)

Helper method to only get the plain addresses.

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **addressesString** ;

**Returns:** [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) an array of plain email addresses extracted from the input string, or an empty array if no valid addresses are found.

**Sample**

```js
var plainArray = plugins.mail.getPlainMailAddresses('John Cobb <from_me@example.com>,Pete Cobb<from_pete@example.com>');
application.output(plainArray[0]) //will return 'from_me@example.com'
```

### isValidEmailAddress(email)

Checks whether the given e-mail address is valid or not.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **email** ;

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if the given email address is valid, false otherwise.

**Sample**

```js
plugins.mail.isValidEmailAddress("me@example.com");
```

### receiveMail(username, password, leaveMsgsOnServer)

Receive mails from pop3 account.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **username** ;
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **password** ;
* [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) **leaveMsgsOnServer** ;

**Returns:** [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) an array of MailMessage objects representing received mail, or null if an error occurred.

**Sample**

```js
var msgs = plugins.mail.receiveMail('mylogin', 'secretpass',  true);
if (msgs != null) //if is null error occurred!
{
	for (var i = 0 ; i < msgs.length ; i++)
	{
		var msg = msgs[i]
		application.output(msg.getFromAddresses())
		application.output(msg.getRecipientAddresses())
		application.output(msg.getReplyAddresses())
		application.output(msg.getSentDate())
		application.output(msg.getHeaders())
		application.output(msg.getSubject())
		application.output(msg.getHtmlMsg())
		application.output(msg.getPlainMsg())
		var attachments = msg.getAttachments()
		if (attachments != null)
		{
			for (var j = 0 ; j < attachments.length ; j++)
			{
				var attachment = attachments[j]
				application.output(attachment.getName())
				var attachmentDataByteArray = attachment.getData()
				//write attachmentDataByteArray to a file...
			}
		}
	}
}
```

### receiveMail(username, password, leaveMsgsOnServer, receiveMode)

Receive mails from pop3 account.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **username** ;
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **password** ;
* [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) **leaveMsgsOnServer** ;
* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **receiveMode** ;

**Returns:** [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) an array of MailMessage objects representing received mail, or null if an error occurred.

**Sample**

```js
var receiveMode = 1;//0=FULL,1=HEADERS_ONLY,2=NO_ATTACHMENTS
var msgs = plugins.mail.receiveMail('mylogin', 'secretpass',  true,  0);
if (msgs != null) //if is null error occurred!
{
	for (var i = 0 ; i < msgs.length ; i++)
	{
		var msg = msgs[i]
		application.output(msg.getFromAddresses())
		application.output(msg.getRecipientAddresses())
		application.output(msg.getReplyAddresses())
		application.output(msg.getSentDate())
		application.output(msg.getHeaders())
		application.output(msg.getSubject())
	}
}
```

### receiveMail(username, password, leaveMsgsOnServer, receiveMode, onlyReceiveMsgWithSentDate)

Receive mails from pop3 account.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **username** ;
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **password** ;
* [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) **leaveMsgsOnServer** ;
* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **receiveMode** ;
* [Date](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/date) **onlyReceiveMsgWithSentDate** ;

**Returns:** [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) an array of MailMessage objects representing received mail, or null if an error occurred.

**Sample**

```js
//it is also possible to first receive the headers and later receive a full message with particular 'sentdate'
//var receiveMode = 1;//0=FULL,1=HEADERS_ONLY,2=NO_ATTACHMENTS
var msgs = plugins.mail.receiveMail('mylogin', 'secretpass',  true,  0,  theSentDateObjectFormPreviousHeaderLoading);
if (msgs != null) //if is null error occurred!
{
	for (var i = 0 ; i < msgs.length ; i++)
	{
		var msg = msgs[i]
		application.output(msg.getFromAddresses())
		application.output(msg.getRecipientAddresses())
		application.output(msg.getReplyAddresses())
		application.output(msg.getSentDate())
		application.output(msg.getHeaders())
		application.output(msg.getSubject())
	}
}
```

### receiveMail(username, password, leaveMsgsOnServer, receiveMode, onlyReceiveMsgWithSentDate, pop3Host)

Receive mails from pop3 account.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **username** ;
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **password** ;
* [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) **leaveMsgsOnServer** ;
* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **receiveMode** ;
* [Date](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/date) **onlyReceiveMsgWithSentDate** ;
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **pop3Host** ;

**Returns:** [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) an array of MailMessage objects representing received mail, or null if an error occurred.

**Sample**

```js
//it is also possible to first receive the headers and later receive a full message
var receiveMode = 0;//0=FULL,1=HEADERS_ONLY,2=NO_ATTACHMENTS
var pop3Host = 'myserver.com';
var msgs = plugins.mail.receiveMail('mylogin', 'secretpass',  true,  receiveMode,  null, pop3Host);
if (msgs != null) //if is null error occurred!
{
	for (var i = 0 ; i < msgs.length ; i++)
	{
		var msg = msgs[i]
		application.output(msg.getFromAddresses())
		application.output(msg.getRecipientAddresses())
		application.output(msg.getReplyAddresses())
		application.output(msg.getSentDate())
		application.output(msg.getHeaders())
		application.output(msg.getSubject())
		application.output(msg.getHtmlMsg())
		application.output(msg.getPlainMsg())
		var attachments = msg.getAttachments()
		if (attachments != null)
		{
			for (var j = 0 ; j < attachments.length ; j++)
			{
				var attachment = attachments[j]
				application.output(attachment.getName())
				var attachmentDataByteArray = attachment.getData()
				//write attachmentDataByteArray to a file...
			}
		}
	}
}
```

### receiveMail(username, password, leaveMsgsOnServer, receiveMode, onlyReceiveMsgWithSentDate, properties)

Receive mails from pop3 account.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **username** ;
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **password** ;
* [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) **leaveMsgsOnServer** ;
* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **receiveMode** ;
* [Date](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/date) **onlyReceiveMsgWithSentDate** ;
* [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) **properties** ;

**Returns:** [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) an array of MailMessage objects representing received mail, or null if an error occurred.

**Sample**

```js
var receiveMode = 1;//0=FULL,1=HEADERS_ONLY,2=NO_ATTACHMENTS

var properties = new Array();
properties[0] = 'mail.pop3.port=995';
properties[1] = 'mail.pop3.ssl.enable=true';
properties[2] = 'mail.pop3.host=myserver.com';
properties[3] = 'mail.pop3.user=user@myserver.com';

var msgs = plugins.mail.receiveMail('mylogin', 'secretpass',  true,  receiveMode,  null, properties);
if (msgs != null) //if is null error occurred!
{
	for (var i = 0 ; i < msgs.length ; i++)
	{
		var msg = msgs[i]
		application.output(msg.getFromAddresses())
		application.output(msg.getRecipientAddresses())
		application.output(msg.getReplyAddresses())
		application.output(msg.getSentDate())
		application.output(msg.getHeaders())
		application.output(msg.getSubject())
	}
}
```

### sendBulkMail(to, from, subject, msgText)

Send a bulk mail, if you make the msgText start with \<html> the message will be sent in html (and you can use all html formatting). A bulk email makes it possible for one to not receive "out of office" emails back from receiver.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **to** A string containing 1 or multiple addresses separated by a comma.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **from** A string containing an address and optional reply addresses, separated by commas.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **subject** The subject of the bulk mail
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **msgText** The message text

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if the bulk email is successfully sent to all specified recipients, or false if an error occurs.

**Sample**

```js
var msgText = 'plain msg<html>styled html msg<img src="%%embedded%%"></html>';
var success = plugins.mail.sendBulkMail('to_someone@example.com,to_someone_else@example.net', 'John Cobb <from_me@example.com>,replyTo@example.com', 'subject', msgText);
if (!success)
{
	plugins.dialogs.showWarningDialog('Alert','Failed to send bulk mail','OK');
}
```

### sendBulkMail(to, from, subject, msgText, cc)

Send a bulk mail, if you make the msgText start with \<html> the message will be sent in html (and you can use all html formatting). A bulk email makes it possible for one to not receive "out of office" emails back from receiver.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **to** A string containing 1 or multiple addresses separated by a comma.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **from** A string containing an address and optional reply addresses, separated by commas.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **subject** The subject of the bulk mail
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **msgText** The message text
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **cc** One or more addresses separated by a comma

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if the bulk email, including “cc” recipients, is sent successfully, or false otherwise.

**Sample**

```js
var msgText = 'plain msg<html>styled html msg<img src="%%embedded%%"></html>';
var success = plugins.mail.sendBulkMail('to_someone@example.com,to_someone_else@example.net', 'John Cobb <from_me@example.com>', 'subject', msgText,'cc1@example.com,cc2@example.com');
if (!success)
{
	plugins.dialogs.showWarningDialog('Alert','Failed to send bulk mail','OK');
}
```

### sendBulkMail(to, from, subject, msgText, cc, bcc)

Send a bulk mail, if you make the msgText start with \<html> the message will be sent in html (and you can use all html formatting). A bulk email makes it possible for one to not receive "out of office" emails back from receiver.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **to** A string containing 1 or multiple addresses separated by a comma.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **from** A string containing an address and optional reply addresses, separated by commas.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **subject** The subject of the bulk mail
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **msgText** The message text
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **cc** One or more addresses separated by a comma
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **bcc** One or more addresses separated by a comma

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if the bulk email is delivered successfully to all specified recipients, including “cc” and “bcc”, or false in case of failure.

**Sample**

```js
var msgText = 'plain msg<html>styled html msg<img src="%%embedded%%"></html>';
var success = plugins.mail.sendBulkMail('to_someone@example.com,to_someone_else@example.net', 'John Cobb <from_me@example.com>', 'subject', msgText,null,'bcc1@example.com');
if (!success)
{
	plugins.dialogs.showWarningDialog('Alert','Failed to send bulk mail','OK');
}
```

### sendBulkMail(to, from, subject, msgText, cc, bcc, attachment)

Send a bulk mail, if you make the msgText start with \<html> the message will be sent in html (and you can use all html formatting). A bulk email makes it possible for one to not receive "out of office" emails back from receiver.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **to** A string containing 1 or multiple addresses separated by a comma.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **from** A string containing an address and optional reply addresses, separated by commas.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **subject** The subject of the bulk mail
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **msgText** The message text
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **cc** One or more addresses separated by a comma
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **bcc** One or more addresses separated by a comma
* [Attachment](https://docs.servoy.com/reference/servoyextensions/server-plugins/mail/attachment) **attachment** A single attachment

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if the bulk email with the specified attachment is sent without issues, or false otherwise.

**Sample**

```js
var attachment = plugins.mail.createBinaryAttachment('embedded',plugins.file.readFile('c:/temp/a_logo.gif'));
var msgText = 'plain msg<html>styled html msg<img src="%%embedded%%"></html>';
var success = plugins.mail.sendBulkMail('to_someone@example.com,to_someone_else@example.net', 'John Cobb <from_me@example.com>', 'subject', msgText,null,'bcc1@example.com,bcc2@example.com',attachment);
if (!success)
{
	plugins.dialogs.showWarningDialog('Alert','Failed to send bulk mail','OK');
}
```

### sendBulkMail(to, from, subject, msgText, cc, bcc, attachment, smtpHost)

Send a bulk mail, if you make the msgText start with \<html> the message will be sent in html (and you can use all html formatting). A bulk email makes it possible for one to not receive "out of office" emails back from receiver.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **to** A string containing 1 or multiple addresses separated by a comma.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **from** A string containing an address and optional reply addresses, separated by commas.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **subject** The subject of the bulk mail
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **msgText** The message text
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **cc** One or more addresses separated by a comma
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **bcc** One or more addresses separated by a comma
* [Attachment](https://docs.servoy.com/reference/servoyextensions/server-plugins/mail/attachment) **attachment** A single attachment
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **smtpHost** The smtp host

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if the bulk email with the specified attachment is sent without issues, or false otherwise.

**Sample**

```js
var attachment = plugins.mail.createBinaryAttachment('embedded',plugins.file.readFile('c:/temp/a_logo.gif'));
var msgText = 'plain msg<html>styled html msg<img src="%%embedded%%"></html>';
var smtphost = 'myserver.com';
var success = plugins.mail.sendBulkMail('to_someone@example.com,to_someone_else@example.net', 'John Cobb <from_me@example.com>', 'subject', msgText,null,'unnamed@example.com',attachment,smtphost);
if (!success)
{
	plugins.dialogs.showWarningDialog('Alert','Failed to send bulk mail','OK');
}
```

### sendBulkMail(to, from, subject, msgText, cc, bcc, attachment, overrideProperties)

Send a bulk mail, if you make the msgText start with \<html> the message will be sent in html (and you can use all html formatting). A bulk email makes it possible for one to not receive "out of office" emails back from receiver.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **to** A string containing 1 or multiple addresses separated by a comma.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **from** A string containing an address and optional reply addresses, separated by commas.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **subject** The subject of the bulk mail
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **msgText** The message text
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **cc** One or more addresses separated by a comma
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **bcc** One or more addresses separated by a comma
* [Attachment](https://docs.servoy.com/reference/servoyextensions/server-plugins/mail/attachment) **attachment** A single attachment
* [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) **overrideProperties** An array of properties

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if the bulk email with the specified attachment is sent without issues, or false otherwise.

**Sample**

```js
var attachment = plugins.mail.createBinaryAttachment('embedded',plugins.file.readFile('c:/temp/a_logo.gif'));
var msgText = 'plain msg<html>styled html msg<img src="%%embedded%%"></html>';
//it is possbile to set all kind of smtp properties
var properties = new Array()
properties[0] = 'mail.smtp.host=myserver.com'
// properties specification can be found at:https://javaee.github.io/javamail/docs/api/com/sun/mail/smtp/package-summary.html
var success = plugins.mail.sendBulkMail('to_someone@example.com,to_someone_else@example.net', 'John Cobb <from_me@example.com>', 'subject', msgText,null,'unnamed@example.com',attachment,properties);
if (!success)
{
	plugins.dialogs.showWarningDialog('Alert','Failed to send bulk mail','OK');
}
```

### sendBulkMail(to, from, subject, msgText, cc, bcc, attachments)

Send a bulk mail, if you make the msgText start with \<html> the message will be sent in html (and you can use all html formatting). A bulk email makes it possible for one to not receive "out of office" emails back from receiver.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **to** A string containing 1 or multiple addresses separated by a comma.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **from** A string containing an address and optional reply addresses, separated by commas.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **subject** The subject of the bulk mail
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **msgText** The message text
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **cc** One or more addresses separated by a comma
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **bcc** One or more addresses separated by a comma
* [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) **attachments** The attachments

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if the bulk email with the specified attachments is sent without issues, or false otherwise.

**Sample**

```js
var attachment1 = plugins.mail.createBinaryAttachment('embedded',plugins.file.readFile('c:/temp/a_logo.gif'));
var attachment2 = plugins.mail.createTextAttachment('embedded','A text attachement');
var msgText = 'plain msg<html>styled html msg<img src="%%embedded%%"></html>';
var success = plugins.mail.sendBulkMail('to_someone@example.com,to_someone_else@example.net', 'John Cobb <from_me@example.com>', 'subject', msgText,null,'bcc1@example.com,bcc2@example.com',[attachment1,attachment2]);
if (!success)
{
	plugins.dialogs.showWarningDialog('Alert','Failed to send bulk mail','OK');
}
```

### sendBulkMail(to, from, subject, msgText, cc, bcc, attachments, smtpHost)

Send a bulk mail, if you make the msgText start with \<html> the message will be sent in html (and you can use all html formatting). A bulk email makes it possible for one to not receive "out of office" emails back from receiver.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **to** A string containing 1 or multiple addresses separated by a comma.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **from** A string containing an address and optional reply addresses, separated by commas.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **subject** The subject of the bulk mail
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **msgText** The message text
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **cc** One or more addresses separated by a comma
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **bcc** One or more addresses separated by a comma
* [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) **attachments** The attachments
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **smtpHost** The smtp host

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if the bulk email with the specified attachments is sent without issues, or false otherwise.

**Sample**

```js
var attachment1 = plugins.mail.createBinaryAttachment('embedded',plugins.file.readFile('c:/temp/a_logo.gif'));
var attachment2 = plugins.mail.createTextAttachment('embedded','A text attachement');
var msgText = 'plain msg<html>styled html msg<img src="%%embedded%%"></html>';
var smtphost = 'myserver.com';
var success = plugins.mail.sendBulkMail('to_someone@example.com,to_someone_else@example.net', 'John Cobb <from_me@example.com>', 'subject', msgText,null,'unnamed@example.com',[attachment1,attachement2],smtphost);
if (!success)
{
	plugins.dialogs.showWarningDialog('Alert','Failed to send bulk mail','OK');
}
```

### sendBulkMail(to, from, subject, msgText, cc, bcc, attachments, overrideProperties)

Send a bulk mail, if you make the msgText start with \<html> the message will be sent in html (and you can use all html formatting). A bulk email makes it possible for one to not receive "out of office" emails back from receiver.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **to** A string containing 1 or multiple addresses separated by a comma.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **from** A string containing an address and optional reply addresses, separated by commas.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **subject** The subject of the bulk mail
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **msgText** The message text
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **cc** One or more addresses separated by a comma
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **bcc** One or more addresses separated by a comma
* [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) **attachments** The attachments
* [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) **overrideProperties** An array of properties

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if the bulk mail was successfully sent, false otherwise.

**Sample**

```js
var attachment1 = plugins.mail.createBinaryAttachment('embedded',plugins.file.readFile('c:/temp/a_logo.gif'));
var attachment2 = plugins.mail.createTextAttachment('embedded','A text attachement');
var msgText = 'plain msg<html>styled html msg<img src="%%embedded%%"></html>';
//it is possbile to set all kind of smtp properties
var properties = new Array()
properties[0] = 'mail.smtp.host=myserver.com'
// properties specification can be found at:https://javaee.github.io/javamail/docs/api/com/sun/mail/smtp/package-summary.html
var success = plugins.mail.sendBulkMail('to_someone@example.com,to_someone_else@example.net', 'John Cobb <from_me@example.com>', 'subject', msgText,null,'unnamed@example.com',[attachment1,attachement2],properties);
if (!success)
{
	plugins.dialogs.showWarningDialog('Alert','Failed to send bulk mail','OK');
}
```

### sendMail(to, from, subject, msgText)

Send a mail, if you make the msgText start with \<html> the message will be sent in html (and you can use all html formatting). If you want to have a different reply address than from, you can specify this with the from parameter by adding another email after it.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **to** A string containing 1 or multiple addresses separated by a comma.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **from** A string containing an address and optional reply addresses, separated by commas.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **subject** The subject of the mail
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **msgText** The message text

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if the email is sent successfully, false otherwise.

**Sample**

```js
var msgText = 'plain msg<html>styled html msg<img src="%%embedded%%"></html>';
var success = plugins.mail.sendMail('to_someone@example.com,to_someone_else@example.net', 'John Cobb <from_me@example.com>,replyTo@example.com', 'subject', msgText);
if (!success)
{
	plugins.dialogs.showWarningDialog('Alert','Failed to send mail','OK');
}
```

### sendMail(to, from, subject, msgText, cc)

Send a mail, if you make the msgText start with \<html> the message will be sent in html (and you can use all html formatting). If you want to have a different reply address than from, you can specify this with the from parameter by adding another email after it.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **to** A string containing 1 or multiple addresses separated by a comma.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **from** A string containing an address and optional reply addresses, separated by commas.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **subject** The subject of the mail
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **msgText** The message text
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **cc** One or more addresses separated by a comma

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if the email is sent, including to recipients in the “cc” field, or false in case of failure.

**Sample**

```js
var msgText = 'plain msg<html>styled html msg<img src="%%embedded%%"></html>';
var success = plugins.mail.sendMail('to_someone@example.com,to_someone_else@example.net', 'John Cobb <from_me@example.com>', 'subject', msgText,'cc1@example.com,cc2@example.com');
if (!success)
{
	plugins.dialogs.showWarningDialog('Alert','Failed to send mail','OK');
}
```

### sendMail(to, from, subject, msgText, cc, bcc)

Send a mail, if you make the msgText start with \<html> the message will be sent in html (and you can use all html formatting). If you want to have a different reply address than from, you can specify this with the from parameter by adding another email after it.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **to** A string containing 1 or multiple addresses separated by a comma.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **from** A string containing an address and optional reply addresses, separated by commas.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **subject** The subject of the mail
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **msgText** The message text
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **cc** One or more addresses separated by a comma
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **bcc** One or more addresses separated by a comma

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if the email is sent successfully, covering both “cc” and “bcc” recipients, or false if an error occurs.

**Sample**

```js
var msgText = 'plain msg<html>styled html msg<img src="%%embedded%%"></html>';
var success = plugins.mail.sendMail('to_someone@example.com,to_someone_else@example.net', 'John Cobb <from_me@example.com>', 'subject', msgText,null,'bcc1@example.com');
if (!success)
{
	plugins.dialogs.showWarningDialog('Alert','Failed to send mail','OK');
}
```

### sendMail(to, from, subject, msgText, cc, bcc, attachment)

Send a mail, if you make the msgText start with \<html> the message will be sent in html (and you can use all html formatting). If you want to have a different reply address than from, you can specify this with the from parameter by adding another email after it.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **to** A string containing 1 or multiple addresses separated by a comma.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **from** A string containing an address and optional reply addresses, separated by commas.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **subject** The subject of the mail
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **msgText** The message text
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **cc** One or more addresses separated by a comma
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **bcc** One or more addresses separated by a comma
* [Attachment](https://docs.servoy.com/reference/servoyextensions/server-plugins/mail/attachment) **attachment** A single attachment

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if the email containing the single specified attachment is sent successfully, or false otherwise.

**Sample**

```js
var attachment = plugins.mail.createBinaryAttachment('embedded',plugins.file.readFile('c:/temp/a_logo.gif'));
var msgText = 'plain msg<html>styled html msg<img src="%%embedded%%"></html>';
var success = plugins.mail.sendMail('to_someone@example.com,to_someone_else@example.net', 'John Cobb <from_me@example.com>', 'subject', msgText,null,'bcc1@example.com,bcc2@example.com',attachment);
if (!success)
{
	plugins.dialogs.showWarningDialog('Alert','Failed to send mail','OK');
}
```

### sendMail(to, from, subject, msgText, cc, bcc, attachment, smtpHost)

Send a mail, if you make the msgText start with \<html> the message will be sent in html (and you can use all html formatting). If you want to have a different reply address than from, you can specify this with the from parameter by adding another email after it.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **to** A string containing 1 or multiple addresses separated by a comma.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **from** A string containing an address and optional reply addresses, separated by commas.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **subject** The subject of the mail
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **msgText** The message text
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **cc** One or more addresses separated by a comma
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **bcc** One or more addresses separated by a comma
* [Attachment](https://docs.servoy.com/reference/servoyextensions/server-plugins/mail/attachment) **attachment** A single attachment
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **smtpHost** The smtp host

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if the email containing the single specified attachment is sent successfully, or false otherwise.

**Sample**

```js
var attachment = plugins.mail.createBinaryAttachment('embedded',plugins.file.readFile('c:/temp/a_logo.gif'));
var msgText = 'plain msg<html>styled html msg<img src="%%embedded%%"></html>';
var smtphost = 'myserver.com';
var success = plugins.mail.sendMail('to_someone@example.com,to_someone_else@example.net', 'John Cobb <from_me@example.com>', 'subject', msgText,null,'unnamed@example.com',attachment,smtphost);
if (!success)
{
	plugins.dialogs.showWarningDialog('Alert','Failed to send mail','OK');
}
```

### sendMail(to, from, subject, msgText, cc, bcc, attachment, overrideProperties)

Send a mail, if you make the msgText start with \<html> the message will be sent in html (and you can use all html formatting). If you want to have a different reply address than from, you can specify this with the from parameter by adding another email after it.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **to** A string containing 1 or multiple addresses separated by a comma.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **from** A string containing an address and optional reply addresses, separated by commas.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **subject** The subject of the mail
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **msgText** The message text
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **cc** One or more addresses separated by a comma
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **bcc** One or more addresses separated by a comma
* [Attachment](https://docs.servoy.com/reference/servoyextensions/server-plugins/mail/attachment) **attachment** A single attachment
* [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) **overrideProperties** An array of properties

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if the email containing the single specified attachment is sent successfully, or false otherwise.

**Sample**

```js
var attachment = plugins.mail.createBinaryAttachment('embedded',plugins.file.readFile('c:/temp/a_logo.gif'));
var msgText = 'plain msg<html>styled html msg<img src="%%embedded%%"></html>';
//it is possbile to set all kind of smtp properties
var properties = new Array()
properties[0] = 'mail.smtp.host=myserver.com'
// properties specification can be found at:https://javaee.github.io/javamail/docs/api/com/sun/mail/smtp/package-summary.html
var success = plugins.mail.sendMail('to_someone@example.com,to_someone_else@example.net', 'John Cobb <from_me@example.com>', 'subject', msgText,null,'unnamed@example.com',attachment,properties);
if (!success)
{
	plugins.dialogs.showWarningDialog('Alert','Failed to send mail','OK');
}
```

### sendMail(to, from, subject, msgText, cc, bcc, attachments)

Send a mail, if you make the msgText start with \<html> the message will be sent in html (and you can use all html formatting). If you want to have a different reply address than from, you can specify this with the from parameter by adding another email after it.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **to** A string containing 1 or multiple addresses separated by a comma.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **from** A string containing an address and optional reply addresses, separated by commas.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **subject** The subject of the mail
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **msgText** The message text
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **cc** One or more addresses separated by a comma
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **bcc** One or more addresses separated by a comma
* [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) **attachments** The attachments

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if the email, along with the specified attachments, is sent successfully, or false otherwise.

**Sample**

```js
var attachment1 = plugins.mail.createBinaryAttachment('embedded',plugins.file.readFile('c:/temp/a_logo.gif'));
var attachment2 = plugins.mail.createTextAttachment('embedded','A text attachement');
var msgText = 'plain msg<html>styled html msg<img src="%%embedded%%"></html>';
var success = plugins.mail.sendMail('to_someone@example.com,to_someone_else@example.net', 'John Cobb <from_me@example.com>', 'subject', msgText,null,'bcc1@example.com,bcc2@example.com',[attachment1,attachment2]);
if (!success)
{
	plugins.dialogs.showWarningDialog('Alert','Failed to send mail','OK');
}
```

### sendMail(to, from, subject, msgText, cc, bcc, attachments, smtpHost)

Send a mail, if you make the msgText start with \<html> the message will be sent in html (and you can use all html formatting). If you want to have a different reply address than from, you can specify this with the from parameter by adding another email after it.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **to** A string containing 1 or multiple addresses separated by a comma.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **from** A string containing an address and optional reply addresses, separated by commas.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **subject** The subject of the mail
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **msgText** The message text
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **cc** One or more addresses separated by a comma
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **bcc** One or more addresses separated by a comma
* [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) **attachments** The attachments
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **smtpHost** The smtp host

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if the email is dispatched with the specified attachments and overridden properties, or false if sending fails.

**Sample**

```js
var attachment1 = plugins.mail.createBinaryAttachment('embedded',plugins.file.readFile('c:/temp/a_logo.gif'));
var attachment2 = plugins.mail.createTextAttachment('embedded','A text attachement');
var msgText = 'plain msg<html>styled html msg<img src="%%embedded%%"></html>';
var smtphost = 'myserver.com';
var success = plugins.mail.sendMail('to_someone@example.com,to_someone_else@example.net', 'John Cobb <from_me@example.com>', 'subject', msgText,null,'unnamed@example.com',[attachment1,attachement2],smtphost);
if (!success)
{
	plugins.dialogs.showWarningDialog('Alert','Failed to send mail','OK');
}
```

### sendMail(to, from, subject, msgText, cc, bcc, attachments, overrideProperties)

Send a mail, if you make the msgText start with \<html> the message will be sent in html (and you can use all html formatting). If you want to have a different reply address than from, you can specify this with the from parameter by adding another email after it.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **to** A string containing 1 or multiple addresses separated by a comma.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **from** A string containing an address and optional reply addresses, separated by commas.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **subject** The subject of the mail
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **msgText** The message text
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **cc** One or more addresses separated by a comma
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **bcc** One or more addresses separated by a comma
* [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) **attachments** The attachments
* [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) **overrideProperties** An array of properties

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if the email is dispatched with the specified attachments and overridden properties, or false if sending fails.

**Sample**

```js
var attachment1 = plugins.mail.createBinaryAttachment('embedded',plugins.file.readFile('c:/temp/a_logo.gif'));
var attachment2 = plugins.mail.createTextAttachment('embedded','A text attachement');
var msgText = 'plain msg<html>styled html msg<img src="%%embedded%%"></html>';
//it is possbile to set all kind of smtp properties
var properties = new Array()
properties[0] = 'mail.smtp.host=myserver.com'
// properties specification can be found at:https://javaee.github.io/javamail/docs/api/com/sun/mail/smtp/package-summary.html
var success = plugins.mail.sendMail('to_someone@example.com,to_someone_else@example.net', 'John Cobb <from_me@example.com>', 'subject', msgText,null,'unnamed@example.com',[attachment1,attachement2],properties);
if (!success)
{
	plugins.dialogs.showWarningDialog('Alert','Failed to send mail','OK');
}
```

***
