/** * {@inheritDoc} * * @see MailSender#createMailConfiguration(com.xpn.xwiki.api.XWiki) */ public MailConfiguration createMailConfiguration(XWiki xwiki) { return new MailConfiguration(xwiki); }
/** * Init a Mail Properties map (exs: smtp, host) * * @return The properties */ private Properties initProperties(MailConfiguration mailConfiguration) { Properties properties = new Properties(); // Note: The full list of available properties that we can set is defined here: // http://java.sun.com/products/javamail/javadocs/com/sun/mail/smtp/package-summary.html properties.put("mail.smtp.port", Integer.toString(mailConfiguration.getPort())); properties.put("mail.smtp.host", mailConfiguration.getHost()); properties.put("mail.smtp.localhost", "localhost"); properties.put("mail.host", "localhost"); properties.put("mail.debug", "false"); if (mailConfiguration.getFrom() != null) { properties.put("mail.smtp.from", mailConfiguration.getFrom()); } if (mailConfiguration.usesAuthentication()) { properties.put("mail.smtp.auth", "true"); } mailConfiguration.appendExtraPropertiesTo(properties, true); return properties; }
public boolean usesAuthentication() { return !StringUtils.isEmpty(getSmtpUsername()) && !StringUtils.isEmpty(getSmtpPassword()); }
@Override public String toString() { StringBuffer buffer = new StringBuffer(); if (getHost() != null) { buffer.append("Host [" + getHost() + "]"); } if (getFrom() != null) { buffer.append(", From [" + getFrom() + "]"); } buffer.append(", Port [" + getPort() + "]"); if (usesAuthentication()) { buffer.append(", Username [" + getSmtpUsername() + "]"); buffer.append(", Password [*****]"); } return buffer.toString(); } }
public MailConfiguration(XWiki xwiki) { this(); String smtpServer = this.mailSenderConfiguration.getHost(); if (!StringUtils.isBlank(smtpServer)) { setHost(smtpServer); } int port = this.mailSenderConfiguration.getPort(); setPort(port); String from = this.mailSenderConfiguration.getFromAddress(); if (!StringUtils.isBlank(from)) { setFrom(from); } String smtpServerUsername = this.mailSenderConfiguration.getUsername(); String smtpServerPassword = this.mailSenderConfiguration.getPassword(); if (!StringUtils.isEmpty(smtpServerUsername) && !StringUtils.isEmpty(smtpServerPassword)) { setSmtpUsername(smtpServerUsername); setSmtpPassword(smtpServerPassword); } Properties javaMailExtraProps = this.mailSenderConfiguration.getAdditionalProperties(); if (!javaMailExtraProps.isEmpty()) { setExtraProperties(javaMailExtraProps); } }
session = Session.getInstance(props, null); transport = session.getTransport("smtp"); if (!mailConfiguration.usesAuthentication()) { transport.connect(mailConfiguration.getSmtpUsername(), mailConfiguration.getSmtpPassword());
public MailConfiguration(XWiki xwiki) { this(); String smtpServer = xwiki.getXWikiPreference("smtp_server"); if (!StringUtils.isBlank(smtpServer)) { setHost(smtpServer); } int port = xwiki.getXWikiPreferenceAsInt("smtp_port", 25); setPort(port); String from = xwiki.getXWikiPreference("smtp_from"); if (!StringUtils.isBlank(from)) { setFrom(from); } String smtpServerUsername = xwiki.getXWikiPreference("smtp_server_username"); String smtpServerPassword = xwiki.getXWikiPreference("smtp_server_password"); if (!StringUtils.isEmpty(smtpServerUsername) && !StringUtils.isEmpty(smtpServerPassword)) { setSmtpUsername(smtpServerUsername); setSmtpPassword(smtpServerPassword); } String javaMailExtraProps = xwiki.getXWikiPreference("javamail_extra_props"); if (!StringUtils.isEmpty(javaMailExtraProps)) { setExtraProperties(javaMailExtraProps); } }
@Override public String toString() { StringBuilder buffer = new StringBuilder(); if (getHost() != null) { buffer.append("Host [" + getHost() + "]"); } if (getFrom() != null) { buffer.append(", From [" + getFrom() + "]"); } buffer.append(", Port [" + getPort() + "]"); if (usesAuthentication()) { buffer.append(", Username [" + getSmtpUsername() + "]"); buffer.append(", Password [*****]"); } return buffer.toString(); } }
session = Session.getInstance(props, null); transport = session.getTransport("smtp"); if (!mailConfiguration.usesAuthentication()) { transport.connect(mailConfiguration.getSmtpUsername(), mailConfiguration.getSmtpPassword());
/** * Init a Mail Properties map (exs: smtp, host) * * @return The properties */ private Properties initProperties(MailConfiguration mailConfiguration) { Properties properties = new Properties(); // Note: The full list of available properties that we can set is defined here: // http://java.sun.com/products/javamail/javadocs/com/sun/mail/smtp/package-summary.html properties.put("mail.smtp.port", Integer.toString(mailConfiguration.getPort())); properties.put("mail.smtp.host", mailConfiguration.getHost()); properties.put("mail.smtp.localhost", "localhost"); properties.put("mail.host", "localhost"); properties.put("mail.debug", "false"); if (mailConfiguration.getFrom() != null) { properties.put("mail.smtp.from", mailConfiguration.getFrom()); } if (mailConfiguration.usesAuthentication()) { properties.put("mail.smtp.auth", "true"); } mailConfiguration.appendExtraPropertiesTo(properties, true); return properties; }
public boolean usesAuthentication() { return !StringUtils.isEmpty(getSmtpUsername()) && !StringUtils.isEmpty(getSmtpPassword()); }
@Override public MailConfiguration createMailConfiguration(XWiki xwiki) { return new MailConfiguration(xwiki); }
/** * Send a Collection of Mails (multiple emails) * * @param emails Mail Collection * @return True in any case (TODO ?) */ public boolean sendMails(Collection<Mail> emails, XWikiContext context) throws MessagingException, UnsupportedEncodingException { // TODO: Fix the need to instantiate a new XWiki API object com.xpn.xwiki.api.XWiki xwikiApi = new com.xpn.xwiki.api.XWiki(context.getWiki(), context); return sendMails(emails, new MailConfiguration(xwikiApi), context); }
/** * Send a single Mail * * @param mailItem The Mail to send * @return True if the the email has been sent */ public boolean sendMail(Mail mailItem, XWikiContext context) throws MessagingException, UnsupportedEncodingException { // TODO: Fix the need to instantiate a new XWiki API object com.xpn.xwiki.api.XWiki xwikiApi = new com.xpn.xwiki.api.XWiki(context.getWiki(), context); return sendMail(mailItem, new MailConfiguration(xwikiApi), context); }
/** * Send a Collection of Mails (multiple emails) * * @param emails Mail Collection * @return True in any case (TODO ?) */ public boolean sendMails(Collection<Mail> emails, XWikiContext context) throws MessagingException, UnsupportedEncodingException { // TODO: Fix the need to instantiate a new XWiki API object com.xpn.xwiki.api.XWiki xwikiApi = new com.xpn.xwiki.api.XWiki(context.getWiki(), context); return sendMails(emails, new MailConfiguration(xwikiApi), context); }
/** * Send a single Mail * * @param mailItem The Mail to send * @return True if the the email has been sent */ public boolean sendMail(Mail mailItem, XWikiContext context) throws MessagingException, UnsupportedEncodingException { // TODO: Fix the need to instantiate a new XWiki API object com.xpn.xwiki.api.XWiki xwikiApi = new com.xpn.xwiki.api.XWiki(context.getWiki(), context); return sendMail(mailItem, new MailConfiguration(xwikiApi), context); }