List of usage examples for org.apache.commons.net.smtp SMTPClient sendSimpleMessage
public boolean sendSimpleMessage(String sender, String[] recipients, String message) throws IOException
From source file:com.discursive.jccook.xml.bean.EmailRule.java
public void end() throws Exception { Message message = (Message) digester.getRoot(); SMTPClient client = new SMTPClient(); client.connect("www.discursive.com"); client.sendSimpleMessage(from, to, message.getText()); }
From source file:com.xpn.xwiki.XWiki.java
/** * @deprecated replaced by the <a href="http://code.xwiki.org/xwiki/bin/view/Plugins/MailSenderPlugin">Mail Sender * Plugin</a>/*from w w w.j a va 2s. c om*/ */ @Deprecated private void sendMessageOld(String sender, String[] recipient, String message, XWikiContext context) throws XWikiException { SMTPClient smtpc = null; try { String server = getXWikiPreference("smtp_server", context); String port = getXWikiPreference("smtp_port", context); String login = getXWikiPreference("smtp_login", context); if (context.get("debugMail") != null) { StringBuffer msg = new StringBuffer(message); msg.append("\n Recipient: "); msg.append(recipient); recipient = ((String) context.get("debugMail")).split(","); message = msg.toString(); } if ((server == null) || server.equals("")) { server = "127.0.0.1"; } if ((port == null) || (port.equals(""))) { port = "25"; } if ((login == null) || login.equals("")) { login = InetAddress.getLocalHost().getHostName(); } smtpc = new SMTPClient(); smtpc.connect(server, Integer.parseInt(port)); int reply = smtpc.getReplyCode(); if (!SMTPReply.isPositiveCompletion(reply)) { Object[] args = { server, port, Integer.valueOf(reply), smtpc.getReplyString() }; throw new XWikiException(XWikiException.MODULE_XWIKI_EMAIL, XWikiException.ERROR_XWIKI_EMAIL_CONNECT_FAILED, "Could not connect to server {0} port {1} error code {2} ({3})", null, args); } if (smtpc.login(login) == false) { reply = smtpc.getReplyCode(); Object[] args = { server, port, Integer.valueOf(reply), smtpc.getReplyString() }; throw new XWikiException(XWikiException.MODULE_XWIKI_EMAIL, XWikiException.ERROR_XWIKI_EMAIL_LOGIN_FAILED, "Could not login to mail server {0} port {1} error code {2} ({3})", null, args); } if (smtpc.sendSimpleMessage(sender, recipient, message) == false) { reply = smtpc.getReplyCode(); Object[] args = { server, port, Integer.valueOf(reply), smtpc.getReplyString() }; throw new XWikiException(XWikiException.MODULE_XWIKI_EMAIL, XWikiException.ERROR_XWIKI_EMAIL_SEND_FAILED, "Could not send mail to server {0} port {1} error code {2} ({3})", null, args); } } catch (IOException e) { Object[] args = { sender, recipient }; throw new XWikiException(XWikiException.MODULE_XWIKI_EMAIL, XWikiException.ERROR_XWIKI_EMAIL_ERROR_SENDING_EMAIL, "Exception while sending email from {0} to {1}", e, args); } finally { if ((smtpc != null) && (smtpc.isConnected())) { try { smtpc.disconnect(); } catch (IOException e) { e.printStackTrace(); } } } }