throws IOException if (!setSender(sender)) { return false;
int count; if (!setSender(sender)) { return false;
@Test public void testSenderDomainResolvDefault() throws Exception { init(smtpConfiguration); SMTPClient smtpProtocol1 = new SMTPClient(); InetSocketAddress bindedAddress = new ProtocolServerUtils(smtpServer).retrieveBindedAddress(); smtpProtocol1.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); smtpProtocol1.helo(InetAddress.getLocalHost().toString()); String sender1 = "mail_sender1@xfwrqqfgfe.de"; smtpProtocol1.setSender(sender1); smtpProtocol1.quit(); }
@Test public void testMultipleMailsAndRset() throws Exception { init(smtpConfiguration); SMTPClient smtpProtocol = new SMTPClient(); InetSocketAddress bindedAddress = new ProtocolServerUtils(smtpServer).retrieveBindedAddress(); smtpProtocol.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); smtpProtocol.sendCommand("ehlo " + InetAddress.getLocalHost()); smtpProtocol.setSender("mail@sample.com"); smtpProtocol.reset(); smtpProtocol.setSender("mail@sample.com"); smtpProtocol.quit(); // mail was propagated by SMTPServer assertThat(queue.getLastMail()) .as("no mail received by mail server") .isNull(); }
@Test public void testRelayingDenied() throws Exception { smtpConfiguration.setAuthorizedAddresses("128.0.0.1/8"); init(smtpConfiguration); SMTPClient smtpProtocol = new SMTPClient(); InetSocketAddress bindedAddress = new ProtocolServerUtils(smtpServer).retrieveBindedAddress(); smtpProtocol.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); smtpProtocol.sendCommand("ehlo " + InetAddress.getLocalHost()); smtpProtocol.setSender("mail@sample.com"); smtpProtocol.addRecipient("maila@sample.com"); assertThat(smtpProtocol.getReplyCode()) .as("expected 550 error") .isEqualTo(550); }
@Test public void testMaxRcptDefault() throws Exception { init(smtpConfiguration); SMTPClient smtpProtocol1 = new SMTPClient(); InetSocketAddress bindedAddress = new ProtocolServerUtils(smtpServer).retrieveBindedAddress(); smtpProtocol1.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); smtpProtocol1.helo(InetAddress.getLocalHost().toString()); String sender1 = "mail_sender1@james.apache.org"; String rcpt1 = "test@localhost"; smtpProtocol1.setSender(sender1); smtpProtocol1.addRecipient(rcpt1); smtpProtocol1.sendShortMessageData("Subject: test\r\n\r\nTest body testMaxRcptDefault\r\n"); smtpProtocol1.quit(); }
@Test public void testHeloEnforcement() throws Exception { init(smtpConfiguration); SMTPClient smtpProtocol1 = new SMTPClient(); InetSocketAddress bindedAddress = new ProtocolServerUtils(smtpServer).retrieveBindedAddress(); smtpProtocol1.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); assertThat(smtpProtocol1.isConnected()) .as("first connection taken") .isTrue(); // no message there, yet assertThat(queue.getLastMail()) .as("no mail received by mail server") .isNull(); String sender1 = "mail_sender1@localhost"; smtpProtocol1.setSender(sender1); assertThat(smtpProtocol1.getReplyCode()) .as("expected 503 error") .isEqualTo(503); smtpProtocol1.helo(InetAddress.getLocalHost().toString()); smtpProtocol1.setSender(sender1); smtpProtocol1.quit(); }
@Test public void testSenderDomainResolvRelayClientDefault() throws Exception { smtpConfiguration.setSenderDomainResolv(); init(smtpConfiguration); SMTPClient smtpProtocol1 = new SMTPClient(); InetSocketAddress bindedAddress = new ProtocolServerUtils(smtpServer).retrieveBindedAddress(); smtpProtocol1.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); assertThat(smtpProtocol1.isConnected()) .as("first connection taken") .isTrue(); // no message there, yet assertThat(queue.getLastMail()) .as("no mail received by mail server") .isNull(); smtpProtocol1.helo(InetAddress.getLocalHost().toString()); String sender1 = "mail_sender1@xfwrqqfgfe.de"; // Both mail shold smtpProtocol1.setSender(sender1); smtpProtocol1.quit(); }
private void send(ProtocolServer server, InetSocketAddress bindedAddress, String msg) throws SocketException, IOException { SMTPClient client = createClient(); client.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).isTrue(); client.helo("localhost"); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).isTrue(); client.setSender(SENDER); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); client.addRecipient(RCPT1); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); client.addRecipient(RCPT2); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); assertThat(client.sendShortMessageData(msg)).isTrue(); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); client.quit(); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); client.disconnect(); }
private void send(ProtocolServer server, InetSocketAddress bindedAddress, String msg) throws SocketException, IOException { SMTPClient client = createClient(); client.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).isTrue(); client.helo("localhost"); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).isTrue(); client.setSender(SENDER); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); client.addRecipient(RCPT1); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); client.addRecipient(RCPT2); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); assertThat(client.sendShortMessageData(msg)).isTrue(); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); client.quit(); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); client.disconnect(); }
@Test public void testHeloEnforcementDisabled() throws Exception { smtpConfiguration.setHeloEhloEnforcement(false); init(smtpConfiguration); SMTPClient smtpProtocol1 = new SMTPClient(); InetSocketAddress bindedAddress = new ProtocolServerUtils(smtpServer).retrieveBindedAddress(); smtpProtocol1.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); assertThat(smtpProtocol1.isConnected()) .as("first connection taken") .isTrue(); // no message there, yet assertThat(queue.getLastMail()) .as("no mail received by mail server") .isNull(); String sender1 = "mail_sender1@localhost"; smtpProtocol1.setSender(sender1); smtpProtocol1.quit(); }
@Test public void testNoRecepientSpecified() throws Exception { init(smtpConfiguration); SMTPClient smtpProtocol = new SMTPClient(); InetSocketAddress bindedAddress = new ProtocolServerUtils(smtpServer).retrieveBindedAddress(); smtpProtocol.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); smtpProtocol.sendCommand("ehlo " + InetAddress.getLocalHost()); smtpProtocol.setSender("mail@sample.com"); // left out for test smtpProtocol.rcpt(new Address("mail@localhost")); smtpProtocol.sendShortMessageData("Subject: test\r\n\r\nTest body testNoRecepientSpecified\r\n"); assertThat(SMTPReply.isNegativePermanent(smtpProtocol.getReplyCode())) .as("sending succeeded without recepient") .isTrue(); smtpProtocol.quit(); // mail was propagated by SMTPServer assertThat(queue.getLastMail()) .as("no mail received by mail server") .isNull(); }
@Test public void testSimpleMailSendWithHELO() throws Exception { init(smtpConfiguration); SMTPClient smtpProtocol = new SMTPClient(); InetSocketAddress bindedAddress = new ProtocolServerUtils(smtpServer).retrieveBindedAddress(); smtpProtocol.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); // no message there, yet assertThat(queue.getLastMail()) .as("no mail received by mail server") .isNull(); smtpProtocol.helo(InetAddress.getLocalHost().toString()); smtpProtocol.setSender("mail@localhost"); smtpProtocol.addRecipient("mail@localhost"); smtpProtocol.sendShortMessageData("Subject: test mail\r\n\r\nTest body testSimpleMailSendWithHELO\r\n.\r\n"); smtpProtocol.quit(); smtpProtocol.disconnect(); // mail was propagated by SMTPServer assertThat(queue.getLastMail()) .as("mail received by mail server") .isNotNull(); }
@Test public void testDNSRBLRejectWorks() throws Exception { smtpConfiguration.setAuthorizedAddresses("192.168.0.1/32"); smtpConfiguration.useRBL(true); init(smtpConfiguration); dnsServer.setLocalhostByName(InetAddress.getByName("127.0.0.1")); SMTPClient smtpProtocol = new SMTPClient(); InetSocketAddress bindedAddress = new ProtocolServerUtils(smtpServer).retrieveBindedAddress(); smtpProtocol.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); smtpProtocol.sendCommand("ehlo", InetAddress.getLocalHost().toString()); String sender = "test_user_smtp@localhost"; smtpProtocol.setSender(sender); smtpProtocol.addRecipient("mail@sample.com"); assertThat(smtpProtocol.getReplyCode()) .as("reject") .isEqualTo(554); smtpProtocol.sendShortMessageData("Subject: test\r\n\r\nTest body testDNSRBLRejectWorks\r\n"); smtpProtocol.quit(); // mail was rejected by SMTPServer assertThat(queue.getLastMail()) .as("mail reject by mail server") .isNull(); }
client.setSender(SENDER); assertThat(SMTPReply.isNegativePermanent(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue();
client.setSender(SENDER); assertThat(SMTPReply.isNegativePermanent(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue();
@Test public void testReceivedHeader() throws Exception { init(smtpConfiguration); SMTPClient smtp = newSMTPClient(); // no message there, yet assertThat(queue.getLastMail()) .as("no mail received by mail server") .isNull();; smtp.helo(InetAddress.getLocalHost().toString()); smtp.setSender("mail@localhost"); smtp.addRecipient("mail@localhost"); smtp.sendShortMessageData("Subject: test\r\n\r\n"); smtp.quit(); smtp.disconnect(); assertThat(queue.getLastMail().getMessage().getHeader("Received")) .as("spooled mail has Received header") .isNotNull(); }
assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue(); client.setSender(""); assertThat(SMTPReply.isPositiveCompletion(client.getReplyCode())).as("Reply=" + client.getReplyString()).isTrue();
@Ignore @Test public void testEmptyMessageReceivedHeader() throws Exception { init(smtpConfiguration); SMTPClient smtp = newSMTPClient(); // no message there, yet assertThat(queue.getLastMail()) .as("no mail received by mail server") .isNull();; smtp.helo(InetAddress.getLocalHost().toString()); smtp.setSender("mail@localhost"); smtp.addRecipient("mail@localhost"); smtp.sendShortMessageData(""); smtp.quit(); smtp.disconnect(); assertThat(queue.getLastMail().getMessage().getHeader("Received")) .as("spooled mail has Received header") .isNotNull(); // TODO: test body size }
@Test public void forwardingAnEmailShouldWork() throws Exception { jmapGuiceProbe.modifyVacation(AccountId.fromString(USER_WITH_DOMAIN), VacationPatch .builder() .isEnabled(true) .textBody(REASON) .build()); String externalMail = "ray@yopmail.com"; SMTPClient smtpClient = new SMTPClient(); smtpClient.connect(LOCALHOST_IP, guiceJamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort()); smtpClient.helo(DOMAIN); smtpClient.setSender(externalMail); smtpClient.rcpt("<" + USER_WITH_DOMAIN + ">"); smtpClient.sendShortMessageData("content"); calmlyAwait.atMost(1, TimeUnit.MINUTES) .untilAsserted(() -> fakeSmtp.assertEmailReceived(response -> response .body("[0].from", equalTo(USER_WITH_DOMAIN)) .body("[0].to[0]", equalTo(externalMail)) .body("[0].text", equalTo(REASON)))); } }