public SMTPMessageSender sendMessage(String from, String recipient) throws IOException { doHelo(); doSetSender(from); doRCPT("<" + recipient + ">"); doData("FROM: " + from + "\r\n" + "subject: test\r\n" + "\r\n" + "content\r\n" + ".\r\n"); return this; }
public static boolean isForStep(Throwable t, SmtpSendingStep step) { if (t instanceof SMTPSendingException) { SMTPSendingException e = (SMTPSendingException) t; return e.sendingStep.equals(step); } return false; }
@Override protected void after() { try { this.close(); } catch (IOException e) { //ignore exception during close } }
@Test void deniedSenderMailShouldBeStoredInCassandraMailRepositoryWhenConfigured(GuiceJamesServer server) throws Exception { server.getProbe(DataProbeImpl.class) .fluent() .addDomain("domain.com") .addUser("user@domain.com", "secret"); smtpMessageSender.connect("127.0.0.1", server.getProbe(SmtpGuiceProbe.class).getSmtpPort()) .sendMessage("denied@other.com", "user@domain.com"); MailRepositoryProbeImpl repositoryProbe = server.getProbe(MailRepositoryProbeImpl.class); await.until(() -> repositoryProbe.getRepositoryMailCount(SENDER_DENIED_URL) == 1); } }
public void initModules() throws Exception { Set<ConfigurationPerformer> processed = processConfigurables(); processOthers(processed); }
public <T extends GuiceProbe> T getProbe(Class<T> probe) { return guiceProbeProvider.getProbe(probe); } }
@Before public void setUp() throws Exception { guiceProbe1 = new GuiceProbe1(); guiceProbeProvider = new GuiceProbeProvider(ImmutableSet.of(guiceProbe1)); }
public static SMTPMessageSender noAuthentication(String ip, int port, String senderDomain) throws IOException { AuthenticatingSMTPClient smtpClient = new AuthenticatingSMTPClient(); smtpClient.connect(ip, port); return new SMTPMessageSender(smtpClient, senderDomain); }
@Before public void setup() { sut = new Configurables(); }
private void doAddRcpt(String rcpt) throws IOException { boolean success = smtpClient.addRecipient(rcpt); if (!success) { throw new SMTPSendingException(SmtpSendingStep.RCPT, smtpClient.getReplyString()); } } }
public String readFirstMessageHeaders() throws IOException { return readFirstMessageInMailbox("(RFC822.HEADER)"); }
public static <U> AllMatching<U> matcher(Matcher<U> matcher) { return new AllMatching<>(matcher); }
@Override public void afterEach(ExtensionContext extensionContext) { after(); }
public SMTPSendingException(SmtpSendingStep sendingStep, String lastServerMessage) { super(String.format("Error upon step %s: %s", sendingStep, lastServerMessage)); this.sendingStep = sendingStep; this.lastServerMessage = sanitizeString(lastServerMessage); }
public SMTPMessageSender sendMessageNoBracket(String from, String recipient) throws IOException { doHelo(); doSetSender(from); doRCPT(recipient); doData("FROM: " + from + "\r\n" + "subject: test\r\n" + "\r\n" + "content\r\n" + ".\r\n"); return this; }
public SMTPMessageSender authenticate(String username, String password) throws IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidKeySpecException { if (smtpClient.auth(AuthenticatingSMTPClient.AUTH_METHOD.PLAIN, username, password) == false) { throw new SMTPSendingException(SmtpSendingStep.Authentication, smtpClient.getReplyString()); } return this; }
public String readFirstMessage() throws IOException { return readFirstMessageInMailbox("(BODY[])"); }
public SMTPMessageSender sendMessageWithHeaders(String from, String recipient, String message) throws IOException { doHelo(); doSetSender(from); doRCPT("<" + recipient + ">"); doData(message); return this; }
private void doHelo() throws IOException { int code = smtpClient.helo(senderDomain); if (code != 250) { throw new SMTPSendingException(SmtpSendingStep.Helo, smtpClient.getReplyString()); } }
private void doData(String message) throws IOException { boolean success = smtpClient.sendShortMessageData(message); if (!success) { throw new SMTPSendingException(SmtpSendingStep.Data, smtpClient.getReplyString()); } }