Example usage for org.apache.commons.net.smtp SMTPSClient helo

List of usage examples for org.apache.commons.net.smtp SMTPSClient helo

Introduction

In this page you can find the example usage for org.apache.commons.net.smtp SMTPSClient helo.

Prototype

public int helo(String hostname) throws IOException 

Source Link

Document

A convenience method to send the SMTP HELO command to the server, receive the reply, and return the reply code.

Usage

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 2 s  .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();
    }
}