Email connector methods
Summarize
Summary of Email connector methods
The Email connector methods enable ServiceNow customers to automate email interactions such as retrieving, sending, replying to messages, and downloading attachments. These methods require initial configuration with theSetConfigmethod to establish a connection to the mail server. Use these methods to handle email processing efficiently within your automation workflows.
Show less
Key Methods and Their Uses
- SetConfig: Must be run first to configure mail server settings and access credentials. It supports parameters like username, password, SMTP/IMAP servers and ports, SSL usage, and default credential options. This setup ensures secure and proper connection before other email operations.
- GetMails: Retrieves emails from a specified IMAP folder, allowing filtering by read or unread status. Returns a collection of messages that subsequent methods can process.
- ReadMail: Reads a single email message, providing details such as subject, body, sender, CC, BCC, and attachment count.
- ReplyMail: Sends an automatic reply to a message, with options to reply to all recipients, include BCC, format the body as HTML, and attach files. Attachments are specified by file paths separated by commas.
- SendMail: Sends new email messages with configurable recipients (To, CC, BCC), subject, body (HTML optional), and attachments, similar to ReplyMail. The sender address is configured via SetConfig.
- SaveAllAttachments: Downloads all attachments from a specified email message to a local directory path.
- MarkAsRead / MarkAsUnread: Marks specific messages in an IMAP folder as read or unread based on the provided email object.
Processing Multiple Messages
Since some methods like ReadMail, ReplyMail, and SaveAllAttachments operate on single messages, when working with multiple emails retrieved by GetMails, use looping constructs such as For Each or For Loop to iterate through each message in the collection. This approach ensures each email is processed individually within the automation.
Practical Application for ServiceNow Customers
By leveraging these Email connector methods, you can automate email workflows directly within ServiceNow automations, such as monitoring inboxes, processing customer requests, replying to emails, and managing attachments without manual intervention. Proper initial configuration with SetConfig is crucial for successful communication with your mail servers. The methods provide flexibility to handle common email tasks securely and efficiently, improving your incident, request, or notification handling processes.
The methods in the Email connector retrieve, send, and reply to email messages, and can download attachments. Use the SetConfig method first to set up the connection to your mail server.
Use the SetConfig method to configure the mail server properties and access credentials. This method must precede all the other Email connector methods in the automation.
The GetMails method retrieves messages from the mail server and passes them to other methods as an object that contains one or more messages. The ReadMail, ReplyMail, and SaveAllAttachments methods operate on a single message at a time. When these methods receive an object that contains more than one message, the automation must use a For Each or For Loop method to iterate each message in the collection.
- For information about how to use the For Each method, see Use the For Each component.
- For information about how to use the For Loop method, see Use the For Loop component.
SetConfig
For information about how to set the parameters, see Configure port properties.
| Parameter | Description | Data port type | Data type | Default value | Required? | Notes |
|---|---|---|---|---|---|---|
| Username | User name to log in to the mail server | Data In | String | (none) | Yes | |
| Password | Password to log in to the mail server | Data In | String | (none) | Yes | |
| UseDefaultCredentials | Sends the default credentials of the currently logged-in user to the SMTP server. | Data In | Boolean | False | No | |
| SmtpMailServer | Name of the SMTP server | Data In | String | smtp.gmail.com | No | Access to Gmail by using the Email connector is not currently supported. Make sure to change the default value. |
| ImapMailServer | Name of the IMAP server | Data In | String | imap.gmail.com | No | Access to Gmail by using the Email connector is not currently supported. Make sure to change the default value. |
| SSL | Use the Secure Socket Layer protocol | Data In | Boolean | True | No | |
| SmtpPort | SMTP port number | Data In | Integer | 587 | No | |
| ImapPort | IMAP port number | Data In | Integer | 993 | No |
GetMails
Returns messages from the mail server for use by other methods. You can set the method to retrieve either read (seen) or unread (unseen) messages and specify the folder that they're gathered.
For information about how to set the parameters, see Configure port properties.
| Parameter | Description | Data port type | Data type | Default value | Required? | Notes |
|---|---|---|---|---|---|---|
| FolderName | Name of the IMAP folder that the method fetches the collection (for example, Inbox) | Data in | String | Inbox | Yes | To specify a nested IMAP folder, enter the folder hierarchy by using backslashes (for example, Project\Meetings) |
| Filter | Set to get only unread (Unseen) or read (Seen) messages | Data in | FilterMode | Unseen | Yes | |
| Return | Returns the mail collection as an object | Data out | Object | Object | Yes |
MarkAsRead
Marks messages from a specified folder as read.
For information about how to set the parameters, see Configure port properties.
| Parameter | Description | Port type | Data type | Default value | Required? | Notes |
|---|---|---|---|---|---|---|
| MailObject | The email object based on which the corresponding message is marked as read | Data in | Object | Object | Yes | |
| FolderName | Name of the IMAP folder that the email object is fetched | Data in | String | Inbox | Yes | To specify a nested IMAP folder, enter the folder hierarchy by using backslashes (for example, Project\Meetings) |
MarkAsUnread
Marks messages from a specified folder as unread.
For information about how to set the parameters, see Configure port properties.
| Parameter | Description | Port type | Data type | Default value | Required? | Notes |
|---|---|---|---|---|---|---|
| MailObject | The email object based on the corresponding email that is marked as unread. | Data in | Object | Object | Yes | |
| FolderName | Name of the IMAP folder that the email object is fetched. | Data in | String | Inbox | Yes | To specify a nested IMAP folder, enter the folder hierarchy by using backslashes (for example, Project\Meetings) |
ReadMail
Reads a message and returns its details, including subject, body, sender (from), recipients in the CC field, recipients in the BCC field, and the number of attachments.
For information about how to set the parameters, see Configure port properties.
| Parameter | Description | Data port type | Data type | Default value | Required? |
|---|---|---|---|---|---|
| MailObject | MailObject that gives the details of the last message received | Data in | Object | Object | Yes |
| Subject | Subject of the message | Data out | String | None | No |
| Body | Body of the message | Data out | String | None | No |
| Sender | Sender of the message | Data out | String | None | No |
| CC | Recipients marked in CC | Data out | String | None | No |
| BCC | Recipients marked in BCC | Data out | String | None | No |
| AttachmentsCount | Number of attachments in the message | Data out | Integer | None | No |
ReplyMail
Automatically replies to a message. Use the parameters to set the body of the message and other details. You can include attachments.
For information about how to set the parameters, see Configure port properties.
| Parameter | Description | Data port type | Data type | Default value | Required? | Notes |
|---|---|---|---|---|---|---|
| MailObject | Message object containing the message details | Data in | Object | Object | Yes | |
| ReplyToAll | Replies to all recipients in the To and CC fields of the message | Data in | Boolean | False | No | |
| BCC | Replies to all recipients in the BCC field of the message | Data in | String | None | No | |
| Body | Body of the reply message | Data in | String | None | No | |
| IsHtmlBody | Option to indicate whether the reply body is in HTML format | Data in | Boolean | False | No | |
| Attachments | Attachments to the reply message | Data in | String | None | No | To attach a file:
To include multiple attachments, separate the paths by commas. |
SaveAllAttachments
Saves all attachments from a message to the local drive.
For information about how to set the parameters, see Configure port properties.
| Parameter | Description | Data port type | Data type | Default value | Required? |
|---|---|---|---|---|---|
| MailObject | Message that the method downloads the attachments from | Data In | Object | Object | Yes |
| FolderPath | Path of the directory to which the attachments are downloaded | Data In | String | None | Yes |
SendMail
For information about how to set the parameters, see Configure port properties.
| Parameter | Description | Data port type | Data type | Default value | Required? | Notes |
|---|---|---|---|---|---|---|
| ToAddress | Address to which to send the message | Data in | String | None | Yes | |
| CC | Addresses to include in the CC field | Data in | String | None | No | |
| BCC | Addresses to include in the BCC field | Data in | String | None | No | |
| Subject | Message subject | Data in | String | None | No | |
| Body | Message body | Data in | String | None | No | |
| IsHtmlBody | Option to indicate whether the reply body is in HTML format | Data in | String | False | No | |
| Attachments | Message attachments | Data in | String | None | No | To attach a file:
To include multiple attachments, separate the paths by commas. |