List of usage examples for org.apache.commons.net.smtp SMTPSClient SMTPSClient
public SMTPSClient()
From source file:adams.core.net.ApacheSendEmail.java
/** * Initializes the SMTP session./* w ww . j a v a2 s . c o m*/ * * @param server the SMTP server * @param port the SMTP port * @param useTLS whether to use TLS * @param useSSL whether to use SSL * @param timeout the timeout * @param requiresAuth whether authentication is required * @param user the SMTP user * @param pw the SMTP password * @return the session * @throws Exception if initialization fails */ @Override public void initializeSmtpSession(String server, int port, boolean useTLS, boolean useSSL, int timeout, boolean requiresAuth, String user, BasePassword pw) throws Exception { m_Server = server; m_Port = port; m_UseTLS = useTLS; m_UseSSL = useSSL; m_Timeout = timeout; m_RequiresAuth = requiresAuth; m_User = user; m_Password = pw; // TODO SSL? if (m_UseTLS) { if (m_RequiresAuth) m_Client = new AuthenticatingSMTPClient(); else m_Client = new SMTPSClient(); } else { m_Client = new SMTPClient(); } m_Client.setConnectTimeout(m_Timeout); if (isLoggingEnabled()) m_Client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out), true)); }
From source file:repl.simple.mathematica.ErrorReporter.java
/** * Sends the information to mail server. * * @param model of bug report/* w w w . j a v a 2s . c o m*/ */ 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(); } }