List of usage examples for org.apache.commons.net.smtp SMTPReply isPositiveCompletion
public static boolean isPositiveCompletion(int reply)
From source file:org.apache.james.protocols.smtp.netty.NettyStartTlsSMTPServerTest.java
@Test public void startTlsShouldFailWhenFollowedByInjectedCommand() throws Exception { server = createServer(createProtocol(Optional.<ProtocolHandler>absent()), Encryption.createStartTls(BogusSslContextFactory.getServerContext())); smtpsClient = createClient();/*w w w . j a va 2 s. com*/ server.bind(); InetSocketAddress bindedAddress = new ProtocolServerUtils(server).retrieveBindedAddress(); smtpsClient.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); smtpsClient.sendCommand("EHLO localhost"); smtpsClient.sendCommand("STARTTLS\r\nRSET\r\n"); assertThat(SMTPReply.isPositiveCompletion(smtpsClient.getReplyCode())).isFalse(); }
From source file:org.apache.james.protocols.smtp.netty.NettyStartTlsSMTPServerTest.java
@Test public void startTlsShouldFailWhenFollowedByInjectedCommandAndNotAtBeginningOfLine() throws Exception { server = createServer(createProtocol(Optional.<ProtocolHandler>absent()), Encryption.createStartTls(BogusSslContextFactory.getServerContext())); smtpsClient = createClient();/*from ww w .ja v a2 s . co m*/ server.bind(); InetSocketAddress bindedAddress = new ProtocolServerUtils(server).retrieveBindedAddress(); smtpsClient.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); smtpsClient.sendCommand("EHLO localhost"); smtpsClient.sendCommand("RSET\r\nSTARTTLS\r\nRSET\r\n"); assertThat(SMTPReply.isPositiveCompletion(smtpsClient.getReplyCode())).isFalse(); }
From source file:repl.simple.mathematica.ErrorReporter.java
/** * Sends the information to mail server. * * @param model of bug report//from w ww . j a v a2s . c om */ private static synchronized void sendBugData(BugReportModel model) { String subject; Writer writer; SimpleSMTPHeader header; SMTPSClient client; // subject = MathREPLBundle.message("reportSubject"); try { header = new SimpleSMTPHeader(model.mailuser, model.to, subject); client = new SMTPSClient(); client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out), true)); client.connect(model.mailserver); if (!SMTPReply.isPositiveCompletion(client.getReplyCode())) { client.disconnect(); throw new ConnectException(MathREPLBundle.message("smtpFailure")); } client.helo("localhost"); if (client.execTLS()) { client.login(); client.setSender(model.mailuser); client.addRecipient(model.to); writer = client.sendMessageData(); if (writer != null) { writer.write(header.toString()); writer.write(model.message); writer.close(); client.completePendingCommand(); } } client.logout(); client.disconnect(); } catch (IOException e) { e.printStackTrace(); } }
From source file:uk.me.sa.android.notify_smtp.net.AuthSMTPTLSClient.java
@Override public boolean auth(AUTH_METHOD method, String username, String password) throws IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidKeySpecException { removeProtocolCommandListener(this); boolean ok = super.auth(method, username, password); if (SMTPReply.isPositiveCompletion(getReplyCode())) { log.info("AUTH {}", getReplyStrings()[0]); } else {//from www .j a va2 s. c om log.error("AUTH {}", getReplyString()); } addProtocolCommandListener(this); return ok; }
From source file:uk.me.sa.android.notify_smtp.net.AuthSMTPTLSClient.java
@Override public void protocolReplyReceived(ProtocolCommandEvent event) { if (SMTPReply.isPositiveCompletion(event.getReplyCode())) { log.info("{} {}", command, getReplyStrings()[0]); } else {/*w ww. ja va 2 s . c o m*/ log.error("{} {}", command, event.getMessage()); } }
From source file:uk.me.sa.android.notify_smtp.net.SendEmail.java
public Boolean call() throws NoSuchAlgorithmException, SocketException, IOException, InvalidKeyException, InvalidKeySpecException { log.info("Sending email: {} ({})", subject, ts); AuthSMTPTLSClient client = new AuthSMTPTLSClient(); client.setDefaultTimeout(TIMEOUT_MS); client.connect(prefs.node, prefs.port); client.setSoTimeout(TIMEOUT_MS); try {/* w w w.j a va 2 s . c o m*/ if (!SMTPReply.isPositiveCompletion(client.getReplyCode())) return false; if (!client.elogin() || !client.execTLS()) return false; if (!client.elogin() || !client.auth(AUTH_METHOD.PLAIN, prefs.username, prefs.password)) return false; if (!client.setSender(prefs.sender)) return false; for (String recipient : prefs.recipients) if (!client.addRecipient(recipient)) return false; if (!client.sendShortMessageData(new Message(subject, ts, prefs.sender, prefs.recipients).toString())) return false; return client.logout(); } finally { client.disconnect(); } }