diff --git a/reply_mails/pom.xml b/reply_mails/pom.xml new file mode 100644 index 0000000..86c88dd --- /dev/null +++ b/reply_mails/pom.xml @@ -0,0 +1,97 @@ + + + 4.0.0 + com.testsigma.addons + reply_mails + 1.0.0 + jar + + + UTF-8 + 11 + 11 + 1.2.8_cloud + 5.8.0-M1 + 1.0.0 + 3.2.1 + 1.18.20 + + + + + + com.testsigma + testsigma-java-sdk + ${testsigma.sdk.version} + + + org.projectlombok + lombok + ${lombok.version} + true + + + org.junit.jupiter + junit-jupiter-api + ${junit.jupiter.version} + test + + + org.testng + testng + 6.14.3 + + + + org.seleniumhq.selenium + selenium-java + 4.14.1 + + + + io.appium + java-client + 9.0.0 + + + com.fasterxml.jackson.core + jackson-annotations + 2.13.0 + + + + + reply_mails + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.4 + + + package + + shade + + + + + + org.apache.maven.plugins + maven-source-plugin + ${maven.source.plugin.version} + + + attach-sources + + jar + + + + + + + \ No newline at end of file diff --git a/reply_mails/src/main/java/com/testsigma/addons/web/SendReplyMails.java b/reply_mails/src/main/java/com/testsigma/addons/web/SendReplyMails.java new file mode 100644 index 0000000..d1edbe2 --- /dev/null +++ b/reply_mails/src/main/java/com/testsigma/addons/web/SendReplyMails.java @@ -0,0 +1,74 @@ +package com.testsigma.addons.web; + +import com.testsigma.sdk.ApplicationType; +import com.testsigma.sdk.annotation.Mailbox; +import com.testsigma.sdk.MailboxMessage; +import com.testsigma.sdk.Result; +import com.testsigma.sdk.WebAction; +import com.testsigma.sdk.annotation.*; +import lombok.Data; +import org.openqa.selenium.NoSuchElementException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +@Data +@Action(actionText = "Reply to the mail with body that contains the subject in mail-name mail-box ", + description = "Reply to the mail that matches the subject in the mail box", + applicationType = ApplicationType.WEB) +public class SendReplyMails extends WebAction { + + private static final String SUCCESS_MESSAGE = "Successfully replied to the mail."; + private static final String MAIL_ERROR_MESSAGE = "Mail contains the given subject not found"; + + @TestData(reference = "body") + private com.testsigma.sdk.TestData body; + @TestData(reference = "subject") + private com.testsigma.sdk.TestData subject; + @TestData(reference = "mail-name") + private com.testsigma.sdk.TestData mail; + + @Mailbox + private com.testsigma.sdk.Mailbox mailbox; + + @Email + private com.testsigma.sdk.Email email; + + @Override + protected Result execute() throws NoSuchElementException { + mailbox.setEmail(mail.toString()); + try { + List messageList = mailbox.getMessages(); + MailboxMessage requiredMessage = null; + for (MailboxMessage message : messageList) { + if (message.getSubject().contains(subject.toString())) { + requiredMessage = message; + break; + } + } + if(requiredMessage == null){ + setErrorMessage(MAIL_ERROR_MESSAGE); + return Result.FAILED; + } + String messageId = email.getMessageId(requiredMessage.getHeaders()); + Map headersList = new HashMap<>(); + headersList.put("In-Reply-To", messageId); + headersList.put("References", messageId); + + List to = new ArrayList<>(); + to.add(requiredMessage.getReceivedFrom()); + email.setTo(to); + email.setSubject("Re:" + subject.toString()); + email.setBody(body.toString()); + email.setHeader(headersList); + email.send(); + setSuccessMessage(SUCCESS_MESSAGE); + return Result.SUCCESS; + } catch (Exception e) { + setErrorMessage(e.toString()); + return Result.FAILED; + } + } +} diff --git a/reply_mails/src/main/resources/testsigma-sdk.properties b/reply_mails/src/main/resources/testsigma-sdk.properties new file mode 100644 index 0000000..47cd21d --- /dev/null +++ b/reply_mails/src/main/resources/testsigma-sdk.properties @@ -0,0 +1 @@ +testsigma-sdk.api.key=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJkZWYtZHNzZndlc2xkbGY0aTg4c2pkZmoiLCJ1bmlxdWVJZCI6IjE3IiwiZXh0ZXJuYWxUZW5hbnRJZCI6IjEifQ.lmcMsU7DUbHCc-9H28o7qIX3XCYixGYNaIKlxzi-jIznhcsqFI5jAkzwoBLiG6m7ByAgcrsT_pe-DW3cf2qhWA \ No newline at end of file