List of usage examples for org.apache.commons.net.smtp SMTPClient SMTPClient
public SMTPClient(String encoding)
From source file:edu.nyu.cs.omnidroid.app.controller.external.actions.GMailService.java
/** * Send a GMail/* w w w. j a v a 2 s.c o m*/ */ private void send() { //Toast.makeText(this, "GMail Service Started", Toast.LENGTH_LONG).show(); SMTPClient client = new SMTPClient("UTF-8"); client.setDefaultTimeout(60 * 1000); client.setRequireStartTLS(true); // requires STARTTLS client.setUseAuth(true); // use SMTP AUTH try { client.connect("smtp.gmail.com", 587); checkReply(client); } catch (IOException e) { //ResultProcessor.process(this, intent, ResultProcessor.RESULT_FAILURE_INTERNET, // getString(R.string.gmail_failed_no_network)); return; } try { client.login("localhost", account.accountName, account.credential); checkReply(client); } catch (IOException e) { ResultProcessor.process(this, intent, ResultProcessor.RESULT_FAILURE_IRRECOVERABLE, getString(R.string.gmail_failed_authentication_error)); return; } try { client.setSender(account.accountName); checkReply(client); client.addRecipient(to); checkReply(client); Writer writer = client.sendMessageData(); if (writer != null) { SimpleSMTPHeader header = new SimpleSMTPHeader(account.accountName, to, subject); writer.write(header.toString()); writer.write(body); writer.close(); client.completePendingCommand(); checkReply(client); } client.logout(); client.disconnect(); } catch (IOException e) { ResultProcessor.process(this, intent, ResultProcessor.RESULT_FAILURE_UNKNOWN, getString(R.string.gmail_failed_server_error)); return; } ResultProcessor.process(this, intent, ResultProcessor.RESULT_SUCCESS, getString(R.string.gmail_sent)); }
From source file:org.csstudio.email.EMailSender.java
/** Initialize * @param host SMTP Host/* ww w . j a va 2 s. c o m*/ * @param from Sender's email * @param to Receiver's email * @param subject Message subject * @throws IOException on I/O error */ public EMailSender(final String host, final String from, final String to, final String subject) throws IOException { smtp = new SMTPClient(host); smtp.setSender(from); smtp.addRecipient(to); message = smtp.sendMessageData(); message.write("To: " + to); message.write("From: " + from); message.write("Subject: " + subject); message.write("Content-Type: multipart/mixed; boundary=\"" + boundary + "\""); message.write("\n"); message.write("This is a multi-part message in MIME format."); message.write("\n"); }