Skip to main content

Validating Emails using Service Suite Scripts

    Create a Script in Service suite as shown below:

     


    Ut7KUVbVwYyBR4fe-f665db7dcdc9.png

    Please refer the below document if the outlook account as 2FA authentication:


    How to create an App Password for an Outlook account and use in service suite script to login to account with 2FA enabled.

    Note: Below is the spec on AIQ mail client

    Mail Client

    >createMailClient(String host, String userMail, String password, String protocol)

    returns a MailService object.

    >MailService object has the following available methods:

      login()

      setFromFolder(String:folder)

      logout()

      getLastUnreadMessages(int:quantity)

      getAllRecipients();

      getFrom();

      message.getSentDate();

      message.getFolder()

      MailMessage byte[] getAttachedFile(String fileName)

      · List<String> getAttachments() //You can get a list with all the names of the attachments from a MailMessage and you can get the file (byte[]) using the file name.

      Sample code snippet


      var mailClient = createMailClient(createMailClient("imap.gmail.com", "myEmail@gmail.com", "App Password", "IMAP");

      trytry{  mailClient.login();}catch (e){
        mailClient.login(mailClient.login();
      }
      catch (e){
        mailClient.login();
      }
      log(log("Login Outlook Account");
      mailClient.setFromFolder(mailClient.setFromFolder("Inbox");
      log(log("Navigate to the Inbox folder");
      //mailClient.setFromFolder("Junk Email");

      var lastUnreadMails = mailClient.getLastUnreadMessages(5)mailClient.getLastUnreadMessages(5);
      var url;
      var attachments;

      //log(lastUnreadMails.size());

      for(for(var i = 0;0; i < lastUnreadMails.size(lastUnreadMails.size(); i+i++){
        if(lastUnreadMailsif(lastUnreadMails.get(i).get(i getFrom().  getFrom().  contains(contains("Appvance")){
            log(log("Fetch the url from this subject" + lastUnreadMailslastUnreadMails.get(i).get(i).getSubject(getSubject());
            log(log("From "+lastUnreadMailslastUnreadMails.get(i).get(i).getFrom(getFrom());        
            log(log("Date "+lastUnreadMailslastUnreadMails.get(i).get(i).getSentDate(getSentDate());
            log(log("Folder "+lastUnreadMailslastUnreadMails.get(i).get(i).getFolder(getFolder());
            log(log("getRecipients "+lastUnreadMailslastUnreadMails.get(i).get(i).getRecipients(getRecipients());
            log(log("Fetch the url from this body" + lastUnreadMailslastUnreadMails.get(i).get(i).getBody(getBody());
            attachments = lastUnreadMailslastUnreadMails.get(i).get(igetAttachments().getAttachments();
            for(for(var j = 0;0; j < attachments.size(attachments.size(); j+j++){
                log(log("Attachment name: "+attachments.get(jattachments.get(j)));
                var bytes =  lastUnreadMailslastUnreadMails.get(i).get(igetAttachedFile(attachments.get(j)).getAttachedFile(attachments.get(j));
                locker.put(locker.put("bytes",bytes)bytes);
                writeBytes(writeBytes("newBytes.pdf", bytes)bytes);
            }
          //code = urlify(lastUnreadMails.get(i).getBody());
        }
       // log("Fetch the url from this body" + lastUnreadMails.get(i).getSubject());
      }
      mailClient.logout(mailClient.logout();



      Note: Replace the valid Email account to test the above methods.

      Outlook Sample


      var mailClient = createMailClient(createMailClient("imap.outlook.com", "aiqtest@outlook.com", "password", "IMAP");

      mailClient.login(mailClient.login();

      mailClient.setFromFolder(mailClient.setFromFolder("Inbox");

      var lastUnreadMails = mailClient.getLastUnreadMessages(1)mailClient.getLastUnreadMessages(1);

      var url = "";

      var from=lastUnreadMailslastUnreadMails.get(0).get(0getFrom().getFrom().contains(contains("Appvance");

      log(from)log(from);



      Last updated: JuneOctober 02,15, 20232026

      If you have any feedback on this topic, please contact us at documentation@appvance.ai