List of usage examples for org.apache.commons.mail Email setTLS
@Deprecated public void setTLS(final boolean withTLS)
From source file:org.pepstock.jem.notify.engine.EmailNotifier.java
/** * This method sends an <code>Email</code>. <br> * It sets in the parameter <code>Email</code> the properties of the * parameter <code>JemEmail</code>: From User Email Address, From User Name, * subject, text, email destination addresses. <br> * It sets in the parameter <code>Email</code> the Email Server property and * the optional <code>SMTP</code> port, the properties that indicates if it * must use <code>SSL</code> and <code>TLS</code> protocol, the useirid and * password for <code>SMTP</code> server authentication if needed, the * optional bounce address, the subject, the text, and the recipients of the * email.//from w w w. jav a 2s . com * * @param email the <code>JemEmail</code> with the properties of the email * to be sent. * @param sendingEmail the real <code>Email</code> that will be sent. * @see JemEmail * @see Email * @throws SendMailException if an error occurs. */ private void sendEmail(JemEmail email, Email sendingEmail) throws SendMailException { try { sendingEmail.setHostName(this.emailServer); if (this.smtpPort != NO_SMTP_PORT) { sendingEmail.setSmtpPort(this.smtpPort); } sendingEmail.setFrom(email.getFromUserEmailAddress(), email.getFromUserName()); if (email.hasSubject()) { sendingEmail.setSubject(email.getSubject()); } else { // log no subject LogAppl.getInstance().emit(NotifyMessage.JEMN014W, "Subject"); } if (email.hasText()) { sendingEmail.setMsg(email.getText()); } else { // log no text message LogAppl.getInstance().emit(NotifyMessage.JEMN014W, "Text Message"); } sendingEmail.setTo(email.getAllToEmailAddresses()); if (null != this.bounceAddress) { sendingEmail.setBounceAddress(this.bounceAddress); } sendingEmail.setSentDate(new Date()); sendingEmail.setSSL(this.isSSL); sendingEmail.setTLS(this.isTLS); if (null != this.authenticationUserId && null != this.authenticationPassword) { sendingEmail.setAuthenticator( new DefaultAuthenticator(this.authenticationUserId, this.authenticationPassword)); } sendingEmail.send(); LogAppl.getInstance().emit(NotifyMessage.JEMN015I, email); } catch (EmailException eEx) { LogAppl.getInstance().emit(NotifyMessage.JEMN016E, eEx, email); throw new SendMailException(NotifyMessage.JEMN016E.toMessage().getFormattedMessage(email), eEx); } }
From source file:org.yestech.notify.deliver.EmailDelivery.java
protected void enableAuthenticator(Email email) { if (isSsl()) { email.setSSL(true);/*www . java 2 s. c o m*/ } if (isTls()) { email.setTLS(true); } if (StringUtils.isNotBlank(getAuthenticatorUserName()) && StringUtils.isNotBlank(getAuthenticatorPassword())) { email.setAuthentication(getAuthenticatorUserName(), getAuthenticatorPassword()); } }
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 w w w . j a va 2s . 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);/* ww w. ja v a 2s . c o m*/ 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; }
From source file:uap.workflow.engine.bpmn.behavior.MailActivityBehavior.java
protected void setMailServerProperties(Email email) { ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration(); String host = processEngineConfiguration.getMailServerHost(); if (host == null) { throw new WorkflowException("Could not send email: no SMTP host is configured"); }/* ww w .j ava2 s . com*/ host = "mail1.ufida.com.cn"; email.setHostName(host); int port = processEngineConfiguration.getMailServerPort(); email.setSmtpPort(port); email.setTLS(processEngineConfiguration.getMailServerUseTLS()); String user = processEngineConfiguration.getMailServerUsername(); user = "tianchw@ufida.com.cn"; String password = processEngineConfiguration.getMailServerPassword(); password = "0670396260/.,mn"; if (user != null && password != null) { email.setAuthentication(user, password); } }