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; }
@Given("^\"([^\"]*)\" receives a SMTP message specified in file \"([^\"]*)\" as message \"([^\"]*)\"$") public void smtpSend(String user, String fileName, String messageName) throws Exception { MailboxId mailboxId = mainStepdefs.mailboxProbe.getMailboxId(MailboxConstants.USER_NAMESPACE, user, INBOX); SMTPMessageSender smtpMessageSender = new SMTPMessageSender("domain.com"); smtpMessageSender .connect("127.0.0.1", mainStepdefs.jmapServer.getProbe(SmtpGuiceProbe.class).getSmtpPort()) .sendMessageWithHeaders("from@domain.com", user, ClassLoaderUtils.getSystemResourceAsString(fileName)); smtpMessageSender.close(); TestingConstants.calmlyAwait.until(() -> !retrieveIds(user, mailboxId).isEmpty()); List<String> ids = retrieveIds(user, mailboxId); messageIdStepdefs.addMessageId(messageName, mainStepdefs.messageIdFactory.fromString(ids.get(0))); }
public SMTPMessageSender sendMessage(Mail mail) throws MessagingException, IOException { String from = mail.getMaybeSender().asString(); doHelo(); doSetSender(from); mail.getRecipients().stream() .map(MailAddress::asString) .forEach(Throwing.consumer(this::doAddRcpt)); doData(asString(mail.getMessage())); return this; }
@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 SMTPMessageSender sendMessage(FakeMail.Builder mail) throws MessagingException, IOException { return sendMessage(mail.build()); }
.recipient(fromAddress) .build(); try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, jmapServer.getProbe(SmtpGuiceProbe.class).getSmtpPort(), DOMAIN)) { messageSender.sendMessage(mail);
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); }
public static SMTPMessageSender authentication(String ip, int port, String senderDomain, String username, String password) throws NoSuchAlgorithmException, IOException, InvalidKeySpecException, InvalidKeyException { AuthenticatingSMTPClient smtpClient = new AuthenticatingSMTPClient(); smtpClient.connect(ip, port); if (smtpClient.auth(AuthenticatingSMTPClient.AUTH_METHOD.PLAIN, username, password) == false) { throw new RuntimeException("auth failed"); } return new SMTPMessageSender(smtpClient, senderDomain); }
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 sendMessageWithHeaders(String from, String recipient, String message) throws IOException { doHelo(); doSetSender(from); doRCPT("<" + recipient + ">"); doData(message); return this; }