List of usage examples for org.apache.commons.mail Email addTo
public Email addTo(final String email, final String name) throws EmailException
From source file:org.mifosplatform.infrastructure.core.service.GmailSendingNotificationToClients.java
public void sendToUserAccount(final String mailAddress, final String approviedDate, final String type, final String money) { final Email email = new SimpleEmail(); final String authuserName = "raghuchiluka111@gmail.com"; final String authuser = "raghuchiluka111@gmail.com"; final String authpwd = "raghuAkhila"; // Very Important, Don't use email.setAuthentication() email.setAuthenticator(new DefaultAuthenticator(authuser, authpwd)); email.setDebug(false); // true if you want to debug email.setHostName("smtp.gmail.com"); email.setSmtpPort(587);// w w w . j a va 2s . c om try { email.getMailSession().getProperties().put("mail.smtp.starttls.enable", "true"); email.setFrom(authuser, authuserName); final StringBuilder subjectBuilder = new StringBuilder().append(type + ": "); email.setSubject(subjectBuilder.toString()); StringBuilder messageBuilder = null; if (money != null) messageBuilder = new StringBuilder().append(type + ": ").append(approviedDate) .append("Amount Disbursed:").append(money); else messageBuilder = new StringBuilder().append(type + ": ").append(approviedDate); email.setMsg(messageBuilder.toString()); email.addTo(mailAddress, mailAddress); email.send(); } catch (final EmailException e) { throw new PlatformEmailSendException(e); } }
From source file:org.opencms.newsletter.CmsNewsletterDistributor.java
/** * Sends a {@link I_CmsNewsletter} to a list of {@link I_CmsNewsletterRecipient} objects.<p> * //w w w .j a v a 2 s .co m * @param recipients a list of CmsNewsletterRecipient objects * @param newsletter the newsletter to be distributed * @param cms the CmsObject */ public void distribute(CmsObject cms, List recipients, I_CmsNewsletter newsletter) { Iterator recipientsIterator = recipients.iterator(); while (recipientsIterator.hasNext()) { I_CmsNewsletterRecipient recipient = (I_CmsNewsletterRecipient) recipientsIterator.next(); try { Email mail = newsletter.getEmail(cms, recipient); mail.addTo(recipient.getEmail(), recipient.getFullName()); mail.send(); } catch (Exception e) { LOG.error(e.getMessage(), e); } } }
From source file:org.ploin.pmf.impl.MailSender.java
private void setMailProperties(Email email, MailConfig mailConfig) throws MailFactoryException { try {/* ww w . j a v a 2 s . c o m*/ email.setSubject(mailConfig.getSubject()); for (Recipient toRecipient : mailConfig.getToRecipients()) { if (toRecipient.getName() != null) { email.addTo(toRecipient.getEmail(), toRecipient.getName()); } else { email.addTo(toRecipient.getEmail()); } } if (!mailConfig.isCcRecipientEmpty()) { for (Recipient ccRecipient : mailConfig.getCcRecipients()) { if (ccRecipient.getName() != null) { email.addCc(ccRecipient.getEmail(), ccRecipient.getName()); } else { email.addCc(ccRecipient.getEmail()); } } } if (!mailConfig.isBccRecipientEmpty()) { for (Recipient bccRecipient : mailConfig.getBccRecipients()) { if (bccRecipient.getName() != null) { email.addBcc(bccRecipient.getEmail(), bccRecipient.getName()); } else { email.addBcc(bccRecipient.getEmail()); } } } } catch (Exception e) { throw new MailFactoryException(e); } }
From source file:org.structr.common.MailHelper.java
private static void setup(final Email mail, final String to, final String toName, final String from, final String fromName, final String cc, final String bcc, final String bounce, final String subject) throws EmailException { // FIXME: this might be slow if the config file is read each time final Properties config = Services.getInstance().getCurrentConfig(); final String smtpHost = config.getProperty(Services.SMTP_HOST, "localhost"); final String smtpPort = config.getProperty(Services.SMTP_PORT, "25"); final String smtpUser = config.getProperty(Services.SMTP_USER); final String smtpPassword = config.getProperty(Services.SMTP_PASSWORD); final String smtpUseTLS = config.getProperty(Services.SMTP_USE_TLS, "true"); final String smtpRequireTLS = config.getProperty(Services.SMTP_REQUIRE_TLS, "false"); mail.setCharset(charset);/*from w w w . j a va 2s.co m*/ mail.setHostName(smtpHost); mail.setSmtpPort(Integer.parseInt(smtpPort)); mail.setStartTLSEnabled(Boolean.parseBoolean(smtpUseTLS)); mail.setStartTLSRequired(Boolean.parseBoolean(smtpRequireTLS)); mail.setCharset(charset); mail.setHostName(smtpHost); mail.setSmtpPort(Integer.parseInt(smtpPort)); if (StringUtils.isNotBlank(smtpUser) && StringUtils.isNotBlank(smtpPassword)) { mail.setAuthentication(smtpUser, smtpPassword); } mail.addTo(to, toName); mail.setFrom(from, fromName); if (StringUtils.isNotBlank(cc)) { mail.addCc(cc); } if (StringUtils.isNotBlank(bcc)) { mail.addBcc(bcc); } if (StringUtils.isNotBlank(bounce)) { mail.setBounceAddress(bounce); } mail.setSubject(subject); }
From source file:org.thousandturtles.gmail_demo.Main.java
public static void main(String[] args) { MailInfoRetriever retriever = new CLIMailInfoRetriever(); MailInfo mailInfo = retriever.retrieveMailInfo(); if (mailInfo.isNoAuth()) { System.out.println("Using No auth, mail with aspmx.l.google.com"); } else {// w w w .ja v a 2 s . co m System.out.printf("Username: %s%n", mailInfo.getUsername()); System.out.printf("Password: %c***%c%n", mailInfo.getPassword().charAt(0), mailInfo.getPassword().charAt(mailInfo.getPassword().length() - 1)); } System.out.printf("Mail target: %s%n", mailInfo.getMailTo()); try { Email mail = new SimpleEmail(); if (mailInfo.isNoAuth()) { mail.setHostName("aspmx.l.google.com"); mail.setSmtpPort(25); mail.setFrom("no-reply@thousandturtles.org"); } else { mail.setHostName("smtp.gmail.com"); mail.setSmtpPort(465); mail.setAuthentication(mailInfo.getUsername(), mailInfo.getPassword()); mail.setSSLOnConnect(true); mail.setFrom(mailInfo.getMailer()); } mail.setCharset("UTF-8"); mail.addTo(mailInfo.getMailTo(), "White Mouse"); mail.setSubject(""); mail.setMsg("?\nThis is a test mail!\n"); mail.send(); System.out.println("Mail sent successfully."); } catch (EmailException ee) { ee.printStackTrace(); } }
From source file:org.xmatthew.spy2servers.component.util.EMailUtils.java
/** * <p>//from w w w . jav a 2 s .c o m * parse email receivers info from the map and add to the email receivers list</p> * * @param email commons email instance. * @param receivers receivers map * @throws EmailException Email about exception. */ private static void parseReceivers(Email email, Map<String, String> receivers) throws EmailException { if (receivers != null && receivers.size() > 0) { Iterator<Map.Entry<String, String>> iter = receivers.entrySet().iterator(); Map.Entry<String, String> receiver; while (iter.hasNext()) { receiver = iter.next(); email.addTo(receiver.getKey(), receiver.getValue()); } } }
From source file:ru.codeinside.adm.CheckExecutionDates.java
@TransactionAttribute(REQUIRES_NEW) public Email checkDates(ProcessEngine processEngine) throws EmailException { String emailTo = get(API.EMAIL_TO); String receiverName = get(API.RECEIVER_NAME); String hostName = get(API.HOST); String port = get(API.PORT);//from ww w . j a va2 s . com String senderLogin = get(API.SENDER_LOGIN); String password = get(API.PASSWORD); String emailFrom = get(API.EMAIL_FROM); String senderName = get(API.SENDER_NAME); if (emailTo.isEmpty() || receiverName.isEmpty() || hostName.isEmpty() || port.isEmpty() || senderLogin.isEmpty() || password.isEmpty() || emailFrom.isEmpty() || senderName.isEmpty()) { return null; } List<TaskDates> overdueTasks = new ArrayList<TaskDates>(); List<Bid> overdueBids = new ArrayList<Bid>(); List<TaskDates> endingTasks = new ArrayList<TaskDates>(); List<Bid> endingBids = new ArrayList<Bid>(); List<TaskDates> inactionTasks = new ArrayList<TaskDates>(); Date currentDate = check(overdueTasks, overdueBids, endingTasks, endingBids, inactionTasks); Email email = new SimpleEmail(); email.setSubject("[siu.oep-penza.ru] ?? ? ? " + new SimpleDateFormat("yyyy.MM.dd HH:mm").format(currentDate)); StringBuilder msg = new StringBuilder(); msg.append(" !\n" + " ?? ? ? ?? ? [siu.oep-penza.ru] ") .append(new SimpleDateFormat("yyyy.MM.dd").format(currentDate)) .append(", ?? :\n\n"); int n = 1; n = addTaskList( ", ? ? ??", n, processEngine, overdueTasks, msg); n = addBidList( "?, ? ? ??", n, overdueBids, msg); n = addTaskList( ", ? ?? ?? ?", n, processEngine, endingTasks, msg); n = addBidList( "?, ? ?? ?? ?", n, endingBids, msg); n = addTaskList(", ??? ?:", n, processEngine, inactionTasks, msg); msg.append( " , ? ? ? !\n" + " ? ? ? " + " . 8(8412)23-11-25 (. 45, 46, 47)"); if (n == 1) { return null; } email.setMsg(msg.toString()); email.addTo(emailTo, receiverName); email.setHostName(hostName); email.setSmtpPort(Integer.parseInt(port)); email.setTLS(AdminServiceProvider.getBoolProperty(API.TLS)); email.setAuthentication(senderLogin, password); email.setFrom(emailFrom, senderName); email.setCharset("utf-8"); return email; }
From source file:ru.codeinside.adm.ui.AdminApp.java
private Panel createEmailDatesPanel() { VerticalLayout emailDates = new VerticalLayout(); emailDates.setSpacing(true);// www .j av a2 s .c om emailDates.setMargin(true); emailDates.setSizeFull(); Panel panel2 = new Panel(" ? ??", emailDates); panel2.setSizeFull(); final TextField emailToField = new TextField("e-mail ?:"); emailToField.setValue(get(API.EMAIL_TO)); emailToField.setRequired(true); emailToField.setReadOnly(true); emailToField.addValidator(new EmailValidator(" e-mail ?")); final TextField receiverNameField = new TextField("? ?:"); receiverNameField.setValue(get(API.RECEIVER_NAME)); receiverNameField.setRequired(true); receiverNameField.setReadOnly(true); final TextField emailFromField = new TextField("e-mail ?:"); emailFromField.setValue(get(API.EMAIL_FROM)); emailFromField.setRequired(true); emailFromField.setReadOnly(true); emailFromField.addValidator(new EmailValidator(" e-mail ?")); final TextField senderLoginField = new TextField(" ?:"); senderLoginField.setValue(get(API.SENDER_LOGIN)); senderLoginField.setRequired(true); senderLoginField.setReadOnly(true); final TextField senderNameField = new TextField("? ?:"); senderNameField.setValue(get(API.SENDER_NAME)); senderNameField.setRequired(true); senderNameField.setReadOnly(true); final PasswordField passwordField = new PasswordField(":"); passwordField.setValue(API.PASSWORD); passwordField.setRequired(true); passwordField.setReadOnly(true); final TextField hostField = new TextField("SMTP ?:"); String host = get(API.HOST); hostField.setValue(host == null ? "" : host); hostField.setRequired(true); hostField.setReadOnly(true); final TextField portField = new TextField(":"); String port = get(API.PORT); portField.setValue(port == null ? "" : port); portField.setRequired(true); portField.setReadOnly(true); portField.addValidator(new IntegerValidator(" ")); final CheckBox tls = new CheckBox("? TLS", AdminServiceProvider.getBoolProperty(API.TLS)); tls.setReadOnly(true); final Button save = new Button(""); save.setVisible(false); final Button cancel = new Button(""); cancel.setVisible(false); final Button change = new Button(""); final Button check = new Button(""); check.addListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { String emailTo = get(API.EMAIL_TO); String receiverName = get(API.RECEIVER_NAME); String hostName = get(API.HOST); String port = get(API.PORT); String senderLogin = get(API.SENDER_LOGIN); String password = get(API.PASSWORD); String emailFrom = get(API.EMAIL_FROM); String senderName = get(API.SENDER_NAME); if (emailTo.isEmpty() || receiverName.isEmpty() || hostName.isEmpty() || port.isEmpty() || senderLogin.isEmpty() || password.isEmpty() || emailFrom.isEmpty() || senderName.isEmpty()) { check.getWindow().showNotification("? ? "); return; } Email email = new SimpleEmail(); try { email.setSubject("? ?"); email.setMsg("? ?"); email.addTo(emailTo, receiverName); email.setHostName(hostName); email.setSmtpPort(Integer.parseInt(port)); email.setTLS(AdminServiceProvider.getBoolProperty(API.TLS)); email.setAuthentication(senderLogin, password); email.setFrom(emailFrom, senderName); email.setCharset("utf-8"); email.send(); } catch (EmailException e) { check.getWindow().showNotification(e.getMessage()); return; } check.getWindow().showNotification("? ? "); } }); change.addListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { emailToField.setReadOnly(false); receiverNameField.setReadOnly(false); emailFromField.setReadOnly(false); senderLoginField.setReadOnly(false); senderNameField.setReadOnly(false); passwordField.setReadOnly(false); hostField.setReadOnly(false); portField.setReadOnly(false); tls.setReadOnly(false); change.setVisible(false); check.setVisible(false); save.setVisible(true); cancel.setVisible(true); } }); save.addListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (StringUtils.isEmpty((String) emailToField.getValue()) || StringUtils.isEmpty((String) receiverNameField.getValue()) || StringUtils.isEmpty((String) emailFromField.getValue()) || StringUtils.isEmpty((String) senderNameField.getValue()) || StringUtils.isEmpty((String) senderLoginField.getValue()) || StringUtils.isEmpty((String) passwordField.getValue()) || StringUtils.isEmpty((String) hostField.getValue()) || portField.getValue() == null) { emailToField.getWindow().showNotification(" ?", Window.Notification.TYPE_HUMANIZED_MESSAGE); return; } boolean errors = false; try { emailToField.validate(); } catch (Validator.InvalidValueException ignore) { errors = true; } try { emailFromField.validate(); } catch (Validator.InvalidValueException ignore) { errors = true; } try { portField.validate(); } catch (Validator.InvalidValueException ignore) { errors = true; } if (errors) { return; } set(API.EMAIL_TO, emailToField.getValue()); set(API.RECEIVER_NAME, receiverNameField.getValue()); set(API.EMAIL_FROM, emailFromField.getValue()); set(API.SENDER_LOGIN, senderLoginField.getValue()); set(API.SENDER_NAME, senderNameField.getValue()); set(API.PASSWORD, passwordField.getValue()); set(API.HOST, hostField.getValue()); set(API.PORT, portField.getValue()); set(API.TLS, tls.getValue()); emailToField.setReadOnly(true); receiverNameField.setReadOnly(true); emailFromField.setReadOnly(true); senderLoginField.setReadOnly(true); senderNameField.setReadOnly(true); passwordField.setReadOnly(true); hostField.setReadOnly(true); portField.setReadOnly(true); tls.setReadOnly(true); save.setVisible(false); cancel.setVisible(false); change.setVisible(true); check.setVisible(true); emailToField.getWindow().showNotification("?? ?", Window.Notification.TYPE_HUMANIZED_MESSAGE); } }); cancel.addListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { emailToField.setValue(get(API.EMAIL_TO)); receiverNameField.setValue(get(API.RECEIVER_NAME)); emailFromField.setValue(get(API.EMAIL_FROM)); senderLoginField.setValue(get(API.SENDER_LOGIN)); senderNameField.setValue(get(API.SENDER_NAME)); passwordField.setValue(get(API.PASSWORD)); hostField.setValue(get(API.HOST)); portField.setValue(get(API.PORT)); tls.setValue(AdminServiceProvider.getBoolProperty(API.TLS)); emailToField.setReadOnly(true); receiverNameField.setReadOnly(true); emailFromField.setReadOnly(true); senderLoginField.setReadOnly(true); senderNameField.setReadOnly(true); passwordField.setReadOnly(true); hostField.setReadOnly(true); portField.setReadOnly(true); tls.setReadOnly(true); save.setVisible(false); cancel.setVisible(false); change.setVisible(true); check.setVisible(true); } }); FormLayout fields1 = new FormLayout(); fields1.setSizeFull(); fields1.addComponent(senderLoginField); fields1.addComponent(passwordField); fields1.addComponent(hostField); fields1.addComponent(portField); fields1.addComponent(tls); FormLayout fields2 = new FormLayout(); fields2.setSizeFull(); fields2.addComponent(emailToField); fields2.addComponent(receiverNameField); fields2.addComponent(emailFromField); fields2.addComponent(senderNameField); HorizontalLayout fields = new HorizontalLayout(); fields.setSpacing(true); fields.setSizeFull(); fields.addComponent(fields1); fields.addComponent(fields2); HorizontalLayout buttons = new HorizontalLayout(); buttons.setSpacing(true); buttons.addComponent(change); buttons.addComponent(save); buttons.addComponent(cancel); buttons.addComponent(check); Label label = new Label("?? "); label.addStyleName(Reindeer.LABEL_H2); emailDates.addComponent(label); emailDates.addComponent(fields); emailDates.addComponent(buttons); emailDates.setExpandRatio(fields, 1f); return panel2; }