Skip to main content
Modules

Email

Email

The Email module is responsible for performing e-mail handling actions.

js
await Email.send["v1_0_0"]({
from: 'roberty@dominio.com',
to: 'user@dominio.com',
subject: 'Assunto do e-mail',
html: '<h1>Corpo do e-mail</h1>',
})

Methods

createConnectionConfiguration

Method responsible for creating a connection configuration with an e-mail server.

js
const config = await Email.createConnectionConfiguration["v1_0_0"]({
host: 'smtp.dominio.com',
port: 587,
user: 'roberty@dominio.com',
password: 'senha',
})

Required parameters

  • host: String - address of the e-mail server.
  • port: Number - port of the e-mail server.
  • user: String - user of the e-mail server.
  • password: String - password of the e-mail server.

Optional parameters

  • tls: Boolean - indicates whether the connection will be made via TLS.
  • tlsOptions: Object - TLS options.
  • useCustomSMTP: Boolean - indicates whether the server will be configured as a custom SMTP.

Return

The config constant receives an object with every connection setting, which can be used as a parameter in the other e-mail methods.

downloadAttachments

Method responsible for downloading the attachments of an e-mail.

js
await Email.downloadAttachments["v1_0_0"]({
pathDownload: 'C:/Users/roberty/Downloads',
mail: emails[0]
})

Required parameters

  • pathDownload: String - path where the attachments will be downloaded.
  • mail: Object - e-mail object obtained through the search method.

Optional parameters

This method has no optional parameters.

Return

This method has no return.

getSubject

Method responsible for getting the subject of an e-mail returned by the search method.

js
const subject = Email.getSubject["v1_0_0"]({
mail: emails[0]
})

Required parameters

  • mail: Object - e-mail object obtained through the search method.

Optional parameters

This method has no optional parameters.

Return

The subject constant receives a String with the subject of the e-mail.

getTextContent

Method responsible for getting the plain text content of an e-mail, removing HTML tags.

js
const text = Email.getTextContent["v1_0_0"]({
mail: emails[0]
})

Required parameters

  • mail: Object - e-mail object obtained through the search method.

Optional parameters

This method has no optional parameters.

Return

The text constant receives a String with the plain text content of the e-mail. If the e-mail has plain text, it is returned directly; otherwise, the HTML is converted to text.

markSeen

Method responsible for marking an e-mail as read.

js
await Email.markSeen["v1_0_0"]({
mail: emails[0],
})

Required parameters

  • mail: Object - e-mail object obtained through the search method.

Optional parameters

  • boxName: String - name of the box where the e-mail will be marked as read. Default value: INBOX.

Return

This method has no return.

moveEmail

Method responsible for moving an e-mail from one box to another.

js
await Email.moveEmail["v1_0_0"]({
connection: config,
email: emails[0],
destinationBox: 'Processados',
sourceBox: 'INBOX',
})

Required parameters

  • connection: Object - connection configuration obtained through the createConnectionConfiguration method.
  • email: Object - e-mail object obtained through the search method. It must contain uuid (number) and optionally messageId (string).
  • destinationBox: String - name of the destination box the e-mail will be moved to.

Optional parameters

  • sourceBox: String - name of the origin box where the e-mail is located. Default value: INBOX.

Return

This method has no return.

replyEmail

Method responsible for replying to an e-mail.

js
await Email.replyEmail["v1_0_0"]({
email: emails[0],
from: 'roberty@dominio.com',
html: '<p>Resposta ao e-mail.</p>',
connection: config,
})

Required parameters

  • email: Object - e-mail object obtained through the search method.
  • from: String - e-mail address of the sender of the reply.
  • html: String - HTML body of the reply.

Optional parameters

  • connection: Object - connection configuration obtained through the createConnectionConfiguration method. If it is not provided, it uses the default Roberty SMTP credentials.
  • subject: String - subject of the reply. If it is not provided, it uses the original subject of the e-mail.
  • cc: String - e-mail address for carbon copy (CC).
  • bcc: String - e-mail address for blind carbon copy (BCC).
  • attachments: String[] - paths of the files to be attached.
  • replyToAll: Boolean - if true, it replies to every original addressee. Default value: false.
  • includeOriginal: Boolean - if true, it includes the original e-mail quoted in the body of the reply. Default value: true.

Return

This method has no return.

Method responsible for searching for e-mails in an inbox.

js
const emails = await Email.search["v1_0_0"]({
boxName: 'INBOX',
connection: config,
criteria: {
conditionFlag: 'ALL',
}
})

Required parameters

  • boxName: String - name of the inbox.
  • connection: Object - connection configuration obtained through the createConnectionConfiguration method.
  • criteria: Object - search criteria:
    • conditionFlag: String - search flag. Values: ALL, UNSEEN, SEEN, UNANSWERED, ANSWERED, DELETED, UNDELETED, DRAFT, UNDRAFT, RECENT, OLD, FLAGGED, UNFLAGGED.
    • conditions: Object[] - additional conditions. Each object has:
      • query: String - type of search: BCC, CC, FROM, TO, SUBJECT, TEXT, BODY, KEYWORD.
      • value: String - value to be searched for.
      • typeCondition: String - logical operator: AND | OR. Default value: AND.

Optional parameters

  • skipAttachments: Boolean - when it is true, the attachments are not downloaded during the search. Default value: false.

Return

The emails constant receives an array of e-mail objects that can be used as a parameter in the markSeen, downloadAttachments, moveEmail, replyEmail, getSubject and getTextContent methods.

send

Method responsible for sending an e-mail.

js
await Email.send["v1_0_0"]({
from: 'roberty@dominio.com',
to: 'email@dominio.com',
subject: 'Assunto',
html: '<h1>Body email</h1>',
})

Required parameters

  • from: String - e-mail address of the sender.
  • to: String - e-mail address of the addressee.
  • subject: String - subject of the e-mail.
  • html: String - body of the e-mail in HTML.

Optional parameters

  • cc: String - e-mail address for carbon copy (CC).
  • bcc: String - e-mail address for blind carbon copy (BCC).
  • replyTo: String - address the replies will be directed to.
  • attachments: String[] - paths of the files to be attached.
  • auth: Object - authentication credentials (user: String, pass: String).
  • useCustomSMTP: Boolean - indicates whether a custom SMTP server will be used.
  • host: String - address of the SMTP server.
  • port: Number - port of the SMTP server.
  • secure: Boolean - indicates whether the connection will have TLS encryption.

Return

This method has no return.