List of usage examples for org.apache.commons.mail Email setSmtpPort
public void setSmtpPort(final int aPortNumber)
From source file:com.mirth.connect.server.util.ServerSMTPConnection.java
public void send(String toList, String ccList, String from, String subject, String body, String charset) throws EmailException { Email email = new SimpleEmail(); // Set the charset if it was specified. Otherwise use the system's default. if (StringUtils.isNotBlank(charset)) { email.setCharset(charset);//from w ww. ja va 2 s . c o m } email.setHostName(host); email.setSmtpPort(Integer.parseInt(port)); email.setSocketConnectionTimeout(socketTimeout); email.setDebug(true); if (useAuthentication) { email.setAuthentication(username, password); } if (StringUtils.equalsIgnoreCase(secure, "TLS")) { email.setStartTLSEnabled(true); } else if (StringUtils.equalsIgnoreCase(secure, "SSL")) { email.setSSLOnConnect(true); email.setSslSmtpPort(port); } // These have to be set after the authenticator, so that a new mail session isn't created ConfigurationController configurationController = ControllerFactory.getFactory() .createConfigurationController(); email.getMailSession().getProperties().setProperty("mail.smtp.ssl.protocols", StringUtils.join( MirthSSLUtil.getEnabledHttpsProtocols(configurationController.getHttpsClientProtocols()), ' ')); email.getMailSession().getProperties().setProperty("mail.smtp.ssl.ciphersuites", StringUtils.join( MirthSSLUtil.getEnabledHttpsCipherSuites(configurationController.getHttpsCipherSuites()), ' ')); for (String to : StringUtils.split(toList, ",")) { email.addTo(to); } if (StringUtils.isNotEmpty(ccList)) { for (String cc : StringUtils.split(ccList, ",")) { email.addCc(cc); } } email.setFrom(from); email.setSubject(subject); email.setMsg(body); email.send(); }
From source file:iddb.core.util.MailManager.java
private void setEmailProps(Email email) throws EmailException { email.setFrom(props.getProperty("from"), "IPDB"); if (props.containsKey("bounce")) email.setBounceAddress(props.getProperty("bounce")); if (props.containsKey("host")) email.setHostName(props.getProperty("host")); if (props.containsKey("port")) email.setSmtpPort(Integer.parseInt(props.getProperty("port"))); if (props.containsKey("username")) email.setAuthenticator(//from w w w.j a va 2 s .co m new DefaultAuthenticator(props.getProperty("username"), props.getProperty("password"))); if (props.containsKey("ssl") && props.getProperty("ssl").equalsIgnoreCase("true")) email.setSSL(true); if (props.containsKey("tls") && props.getProperty("tls").equalsIgnoreCase("true")) email.setTLS(true); if (props.containsKey("debug") && props.getProperty("debug").equalsIgnoreCase("true")) email.setDebug(true); }
From source file:net.scran24.user.server.services.HelpServiceImpl.java
@Override public void reportUncaughtException(String strongName, List<String> classNames, List<String> messages, List<StackTraceElement[]> stackTraces, String surveyState) { Subject subject = SecurityUtils.getSubject(); ScranUserId userId = (ScranUserId) subject.getPrincipal(); if (userId == null) throw new RuntimeException("User must be logged in"); String rateKey = userId.survey + "#" + userId.username; RateInfo rateInfo = rateMap.get(rateKey); boolean rateExceeded = false; long time = System.currentTimeMillis(); if (rateInfo == null) { rateMap.put(rateKey, new RateInfo(1, time)); } else {//from w w w . j av a2 s . c o m long timeSinceLastRequest = time - rateInfo.lastRequestTime; if (timeSinceLastRequest > 10000) { rateMap.put(rateKey, new RateInfo(1, time)); } else if (rateInfo.requestCount >= 10) { rateExceeded = true; } else { rateMap.put(rateKey, new RateInfo(rateInfo.requestCount + 1, time)); } } if (!rateExceeded) { System.out.println(String.format("Sending email", userId.survey, userId.username)); Email email = new SimpleEmail(); email.setHostName(smtpHostName); email.setSmtpPort(smtpPort); email.setCharset(EmailConstants.UTF_8); email.setAuthenticator(new DefaultAuthenticator(smtpUserName, smtpPassword)); email.setSSLOnConnect(true); StringBuilder sb = new StringBuilder(); for (int i = 0; i < classNames.size(); i++) { sb.append(String.format("%s: %s\n", classNames.get(i), messages.get(i))); StackTraceElement[] deobfStackTrace = deobfuscator.resymbolize(stackTraces.get(i), strongName); for (StackTraceElement ste : deobfStackTrace) { sb.append(String.format(" %s\n", ste.toString())); } sb.append("\n"); } sb.append("Survey state:\n"); sb.append(surveyState); sb.append("\n"); try { email.setFrom("no-reply@intake24.co.uk", "Intake24"); email.setSubject(String.format("Client exception (%s/%s): %s", userId.survey, userId.username, messages.get(0))); email.setMsg(sb.toString()); email.addTo("bugs@intake24.co.uk"); email.send(); } catch (EmailException ee) { log.error("Failed to send e-mail notification", ee); } } }
From source file:JavaMail.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: try {//from w w w. j ava 2 s.co m String from = jTextField1.getText(); String to = jTextField2.getText(); String subject = jTextField3.getText(); String content = jTextArea1.getText(); Email email = new SimpleEmail(); String provi = prov.getSelectedItem().toString(); if (provi.equals("Gmail")) { email.setHostName("smtp.gmail.com"); email.setSmtpPort(465); serverlink = "smtp.gmail.com"; serverport = 465; } if (provi.equals("Outlook")) { email.setHostName("smtp-mail.outlook.com"); serverlink = "smtp-mail.outlook.com"; email.setSmtpPort(25); serverport = 25; } if (provi.equals("Yahoo")) { email.setHostName("smtp.mail.yahoo.com"); serverlink = "smtp.mail.yahoo.com"; email.setSmtpPort(465); serverport = 465; } System.out.println("Initializing email sending sequence"); System.out.println("Connecting to " + serverlink + " at port " + serverport); JPanel panel = new JPanel(); JLabel label = new JLabel( "Enter the password of your email ID to connect with your Email provider." + "\n"); JPasswordField pass = new JPasswordField(10); panel.add(label); panel.add(pass); String[] options = new String[] { "OK", "Cancel" }; int option = JOptionPane.showOptionDialog(null, panel, "Enter Email ID Password", JOptionPane.NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[1]); if (option == 0) // pressing OK button { char[] password = pass.getPassword(); emailpass = new String(password); } email.setAuthenticator(new DefaultAuthenticator(from, emailpass)); email.setSSLOnConnect(true); if (email.isSSLOnConnect() == true) { System.out.println("This server requires SSL/TLS authentication."); } email.setFrom(from); email.setSubject(subject); email.setMsg(content); email.addTo(to); email.send(); JOptionPane.showMessageDialog(null, "Message sent successfully."); } catch (Exception e) { e.printStackTrace(); } }
From source file:egovframework.rte.tex.com.service.impl.EgovMailServiceImpl.java
/** * ? ?? ?? ./*from w ww . java 2 s. com*/ * @param vo ? * @return ? */ @Override @SuppressWarnings("deprecation") public boolean sendEmailTo(MemberVO vo) { boolean result = false; Email email = new SimpleEmail(); email.setCharset("utf-8"); // ? // setHostName? ? // email.setHostName(mailInfoService.getString("hostName")); // SpEL? properties ? email.setHostName(hostName); // SMTP email.setSmtpPort(port); email.setAuthenticator(new DefaultAuthenticator(mailId, mailPass)); email.setTLS(true); try { email.addTo(vo.getEmail(), vo.getId()); // ? } catch (EmailException e) { e.printStackTrace(); } try { email.setFrom(mailId, mailName); // } catch (EmailException e) { e.printStackTrace(); } email.setSubject(subject); // ? email.setContent("ID: " + vo.getId() + "<br>" + "PASSWORD: " + vo.getPassword(), "text/plain; charset=utf-8"); try { email.send(); result = true; } catch (EmailException e) { e.printStackTrace(); } return result; }
From source file:com.qwazr.connectors.EmailConnector.java
public void sendEmail(Email email) throws EmailException { email.setHostName(hostname);/* ww w. java 2s .c o m*/ if (ssl != null) email.setSSLOnConnect(ssl); if (start_tls_enabled != null) email.setStartTLSEnabled(start_tls_enabled); if (start_tls_required != null) email.setStartTLSRequired(start_tls_required); if (port != null) email.setSmtpPort(port); if (username != null) email.setAuthentication(username, password); if (connection_timeout != null) email.setSocketConnectionTimeout(connection_timeout); if (timeout != null) email.setSocketTimeout(timeout); email.send(); }
From source file:com.qwazr.library.email.EmailConnector.java
public void sendEmail(final Email email) throws EmailException { email.setHostName(hostname);// ww w . j ava2s.c om if (ssl != null) email.setSSLOnConnect(ssl); if (start_tls_enabled != null) email.setStartTLSEnabled(start_tls_enabled); if (start_tls_required != null) email.setStartTLSRequired(start_tls_required); if (port != null) email.setSmtpPort(port); if (username != null) email.setAuthentication(username, password); if (connection_timeout != null) email.setSocketConnectionTimeout(connection_timeout); if (timeout != null) email.setSocketTimeout(timeout); email.send(); }
From source file:com.irurueta.server.commons.email.ApacheMailSender.java
/** * Internal method to send email using Apache Mail. * @param m email message./*from w w w.j a va 2 s .c o m*/ * @param email apache email message. * @throws NotSupportedException if feature is not supported. * @throws EmailException if Apache Mail cannot send email. * @throws com.irurueta.server.commons.email.EmailException if sending * email fails. */ private void internalSendApacheEmail(EmailMessage m, Email email) throws NotSupportedException, EmailException, com.irurueta.server.commons.email.EmailException { email.setHostName(mMailHost); email.setSmtpPort(mMailPort); if (mMailId != null && !mMailId.isEmpty() && mMailPassword != null && !mMailPassword.isEmpty()) { email.setAuthenticator(new DefaultAuthenticator(mMailId, mMailPassword)); } email.setStartTLSEnabled(true); email.setFrom(mMailFromAddress); if (m.getSubject() != null) { email.setSubject(m.getSubject()); } m.buildContent(email); //add destinatoins for (String s : (List<String>) m.getTo()) { email.addTo(s); } for (String s : (List<String>) m.getCC()) { email.addCc(s); } for (String s : (List<String>) m.getBCC()) { email.addBcc(s); } email.send(); }
From source file:edu.corgi.uco.sendEmails.java
public String send(String emailAddress, String studentFirstName, String studentLastName) throws EmailException { System.out.print("hit send"); Email email = new SimpleEmail(); System.out.print("created email file"); email.setDebug(true);/* w ww. j a v a 2 s.com*/ email.setHostName("smtp.gmail.com"); email.setAuthenticator(new DefaultAuthenticator("ucocorgi2@gmail.com", "ucodrsung")); email.setStartTLSEnabled(true); email.setSmtpPort(587); email.setFrom("ucocorgi@gmail.com", "UCO CS Secretary"); email.setSubject("Advisement Update"); email.setMsg(studentFirstName + " " + studentLastName + " your advisment has been processed and the hold on your account will be removed shortly"); System.out.print("Email Address: " + emailAddress); email.addTo(emailAddress); System.out.print("added values"); email.send(); System.out.print("sent"); return null; }
From source file:gov.nih.nci.firebird.service.messages.email.EmailServiceImpl.java
private void initEmailInfo(Email email) throws EmailException { email.setMailSession(mailSession);//from www. ja va 2 s . c o m String smtpPort = email.getMailSession().getProperty(Email.MAIL_PORT); email.setFrom(senderEmail, senderName); if (StringUtils.isNumeric(smtpPort) && Integer.valueOf(smtpPort) > 0) { email.setSmtpPort(Integer.valueOf(smtpPort)); } }