List of usage examples for org.apache.commons.mail Email send
public String send() throws EmailException
From source file:com.mirth.connect.connectors.smtp.SmtpSenderService.java
@Override public Object invoke(String channelId, String method, Object object, String sessionId) throws Exception { if (method.equals("sendTestEmail")) { SmtpDispatcherProperties props = (SmtpDispatcherProperties) object; String host = replacer.replaceValues(props.getSmtpHost(), channelId); String portString = replacer.replaceValues(props.getSmtpPort(), channelId); int port = -1; try {//from w w w . j a v a 2 s . c om port = Integer.parseInt(portString); } catch (NumberFormatException e) { return new ConnectionTestResponse(ConnectionTestResponse.Type.FAILURE, "Invalid port: \"" + portString + "\""); } String secure = props.getEncryption(); boolean authentication = props.isAuthentication(); String username = replacer.replaceValues(props.getUsername(), channelId); String password = replacer.replaceValues(props.getPassword(), channelId); String to = replacer.replaceValues(props.getTo(), channelId); String from = replacer.replaceValues(props.getFrom(), channelId); Email email = new SimpleEmail(); email.setDebug(true); email.setHostName(host); email.setSmtpPort(port); if ("SSL".equalsIgnoreCase(secure)) { email.setSSL(true); } else if ("TLS".equalsIgnoreCase(secure)) { email.setTLS(true); } if (authentication) { email.setAuthentication(username, password); } email.setSubject("Mirth Connect Test Email"); try { for (String toAddress : StringUtils.split(to, ",")) { email.addTo(toAddress); } email.setFrom(from); email.setMsg( "Receipt of this email confirms that mail originating from this Mirth Connect Server is capable of reaching its intended destination.\n\nSMTP Configuration:\n- Host: " + host + "\n- Port: " + port); email.send(); return new ConnectionTestResponse(ConnectionTestResponse.Type.SUCCESS, "Sucessfully sent test email to: " + to); } catch (EmailException e) { return new ConnectionTestResponse(ConnectionTestResponse.Type.FAILURE, e.getMessage()); } } return null; }
From source file:egovframework.rte.tex.com.service.impl.EgovMailServiceImpl.java
/** * ? ?? ?? .//from ww w .j a v a 2s . c om * @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:io.mapzone.controller.email.EmailService.java
public void send(Email email) throws EmailException { String env = System.getProperty("io.mapzone.controller.SMTP"); if (env == null) { throw new IllegalStateException( "Environment variable missing: io.mapzone.controller.SMTPP. Format: <host>|<login>|<passwd>|<from>"); }/* ww w. j a v a 2s. c om*/ String[] parts = StringUtils.split(env, "|"); if (parts.length < 3 || parts.length > 4) { throw new IllegalStateException( "Environment variable wrong: io.mapzone.controller.SMTP. Format: <host>|<login>|<passwd>|<from> : " + env); } email.setDebug(true); email.setHostName(parts[0]); //email.setSmtpPort( 465 ); //email.setSSLOnConnect( true ); email.setAuthenticator(new DefaultAuthenticator(parts[1], parts[2])); if (email.getFromAddress() == null && parts.length == 4) { email.setFrom(parts[3]); } if (email.getSubject() == null) { throw new EmailException("Missing subject."); } email.send(); }
From source file:com.patrolpro.beans.SignupClientBean.java
public String sendEmail() { try {//from w ww.ja v a 2s . co m boolean isValid = validateInformation(); if (isValid) { StringBuilder emailMessage = new StringBuilder(); emailMessage.append("Contact Name: " + this.contactName + "\r\n"); emailMessage.append("Contact Email: " + this.contactEmail + "\r\n"); emailMessage.append("Contact Phone: " + this.contactPhone + "\r\n"); emailMessage.append("Company Name: " + this.companyName + "\r\n"); emailMessage.append(message); Email htmlEmail = new SimpleEmail(); if (message == null || message.length() == 0) { message = "No message was provided by the user."; } htmlEmail.setFrom("signup@patrolpro.com"); htmlEmail.setSubject("Trial Account Email!"); htmlEmail.addTo("rharris@ainteractivesolution.com"); htmlEmail.addTo("ijuneau@ainteractivesolution.com"); htmlEmail.addCc("jc@champ.net"); //htmlEmail.setHtmlMsg(emailMessage.toString()); htmlEmail.setMsg(emailMessage.toString()); //htmlEmail.setTextMsg(emailMessage.toString()); htmlEmail.setDebug(true); htmlEmail.setAuthenticator(new MailAuthenticator("schedfox", "Sch3dF0x4m3")); htmlEmail.setHostName("mail2.champ.net"); htmlEmail.setSmtpPort(587); htmlEmail.send(); return "sentEmail"; } } catch (Exception exe) { } return "invalid"; }
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 av a 2 s. c om*/ * @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:com.googlecode.fascinator.messaging.EmailNotificationConsumer.java
private void sendEmails(List<String> toList, List<String> ccList, String subject, String body, String fromAddress, String fromName, boolean isHtml) throws EmailException { Email email = null; if (isHtml) { email = new HtmlEmail(); ((HtmlEmail) email).setHtmlMsg(body); } else {//from w w w . ja v a 2s.c o m email = new SimpleEmail(); email.setMsg(body); } email.setDebug(debug); email.setHostName(smtpHost); if (smtpUsername != null || smtpPassword != null) { email.setAuthentication(smtpUsername, smtpPassword); } email.setSmtpPort(smtpPort); email.setSslSmtpPort(smtpSslPort); email.setSSL(smtpSsl); email.setTLS(smtpTls); email.setSubject(subject); for (String to : toList) { email.addTo(to); } if (ccList != null) { for (String cc : ccList) { email.addCc(cc); } } email.setFrom(fromAddress, fromName); email.send(); }
From source file:com.neu.controller.MessageController.java
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { DataSource ds = (DataSource) this.getApplicationContext().getBean("myDataSource"); String action = request.getParameter("action"); ModelAndView mv = new ModelAndView(); HttpSession session = request.getSession(); String userName = (String) session.getAttribute("userName"); if (action.equalsIgnoreCase("reply")) { try {/*from www .j av a2 s . c o m*/ String receiver = request.getParameter("to"); System.out.println("Printing receiver in reply case: " + receiver); QueryRunner run = new QueryRunner(ds); ResultSetHandler<UsersBean> user = new BeanHandler<UsersBean>(UsersBean.class); UsersBean ub = run.query("select * from userstable where userName =?", user, receiver); if (ub != null) { System.out.println("printing userEmail received from DB: " + ub.getUserEmail()); mv.addObject("toEmail", ub.getUserEmail()); mv.addObject("to", receiver); } mv.setViewName("reply"); } catch (SQLException e) { System.out.println(e); } } else if (action.equalsIgnoreCase("sent")) { System.out.println("In sent case"); try { String receiver = request.getParameter("to"); String receiverEmail = request.getParameter("toEmail"); System.out.println("printing receiver email: " + receiverEmail); QueryRunner run = new QueryRunner(ds); ResultSetHandler<UsersBean> user = new BeanHandler<UsersBean>(UsersBean.class); UsersBean ub = run.query("select * from userstable where userName =?", user, userName); if (ub != null) { String senderEmail = ub.getUserEmail(); System.out.println("printing senderemail: " + senderEmail); ResultSetHandler<MessageBean> msg = new BeanHandler<MessageBean>(MessageBean.class); Object[] params = new Object[4]; params[0] = userName; params[1] = request.getParameter("message"); Date d = new Date(); SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd"); String messageDate = format.format(d); params[2] = messageDate; params[3] = receiver; int inserts = run.update( "Insert into messages (fromUser,message,messageDate,userName) values(?,?,?,?)", params);//Logic to send the email try { Email email = new SimpleEmail(); email.setHostName("smtp.googlemail.com");//If a server is capable of sending email, then you don't need the authentication. In this case, an email server needs to be running on that machine. Since we are running this application on the localhost and we don't have a email server, we are simply asking gmail to relay this email. email.setSmtpPort(465); email.setAuthenticator( new DefaultAuthenticator("contactapplication2017@gmail.com", "springmvc")); email.setSSLOnConnect(true); email.setFrom(senderEmail);//This email will appear in the from field of the sending email. It doesn't have to be a real email address.This could be used for phishing/spoofing! email.setSubject("Thanks for Signing Up!"); email.setMsg("Welcome to Web tools Lab 5 Spring Application sign up email test!"); email.addTo(receiverEmail);//Will come from the database email.send(); } catch (Exception e) { System.out.println("Email Exception" + e.getMessage()); e.printStackTrace(); } mv.setViewName("messageSent"); } else { mv.addObject("error", "true"); mv.setViewName("index"); } } catch (Exception ex) { System.out.println("Error Message" + ex.getMessage()); ex.printStackTrace(); } } return mv; }
From source file:com.neu.controller.LoginController.java
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { DataSource ds = (DataSource) this.getApplicationContext().getBean("myDataSource"); String action = request.getParameter("action"); ModelAndView mv = new ModelAndView(); HttpSession session = request.getSession(); if (action.equalsIgnoreCase("login")) { try {//from w w w. j av a2 s .co m String userName = request.getParameter("user"); String password = request.getParameter("password"); QueryRunner run = new QueryRunner(ds); ResultSetHandler<UsersBean> user = new BeanHandler<UsersBean>(UsersBean.class); Object[] params = new Object[2]; params[0] = userName; params[1] = password; UsersBean ub = run.query("select * from userstable where userName =? and userPassword=?", user, params); if (ub != null) { ResultSetHandler<List<MessageBean>> messages = new BeanListHandler<MessageBean>( MessageBean.class); List<MessageBean> msg = run.query("select * from messages where userName =?", messages, userName); session.setAttribute("userName", userName); session.setAttribute("messageList", msg); mv.setViewName("userhome"); } else { mv.addObject("error", "true"); mv.setViewName("index"); } } catch (Exception ex) { System.out.println("Error Message" + ex.getMessage()); } } else if (action.equalsIgnoreCase("logout")) { session.invalidate(); mv.setViewName("index"); } else if (action.equalsIgnoreCase("signup")) { System.out.println("sign up"); // // String userName = request.getParameter("user"); // String password = request.getParameter("password"); // String emailObj = request.getParameter("emailObj"); // // System.out.println("printing details: " + userName + " " +password + " "+emailObj); mv.setViewName("signup"); } else if (action.equalsIgnoreCase("signupsubmit")) { System.out.println("sign up submit"); String userName = request.getParameter("user"); String password = request.getParameter("password"); String email = request.getParameter("email"); System.out.println("printing details: " + userName + " " + password + " " + email); if (userName.equals("") || (password.equals("")) || (email.equals(""))) { System.out.println("empty values"); mv.addObject("error", "true"); } else { ResultSetHandler<UsersBean> user = new BeanHandler<UsersBean>(UsersBean.class); Object[] params = new Object[3]; params[0] = userName; params[1] = password; params[2] = email; QueryRunner run = new QueryRunner(ds); int inserts = run.update("insert into userstable (UserName,UserPassword,UserEmail) values (?,?,?)", params);//Logic to insert into table System.out.println("inserts value " + inserts); if (inserts > 0) { mv.addObject("success", "true"); Email emailObj = new SimpleEmail(); emailObj.setHostName("smtp.googlemail.com");//If a server is capable of sending emailObj, then you don't need the authentication. In this case, an emailObj server needs to be running on that machine. Since we are running this application on the localhost and we don't have a emailObj server, we are simply asking gmail to relay this emailObj. emailObj.setSmtpPort(465); emailObj.setAuthenticator( new DefaultAuthenticator("contactapplication2017@gmail.com", "springmvc")); emailObj.setSSLOnConnect(true); emailObj.setFrom("webtools@hello.com");//This emailObj will appear in the from field of the sending emailObj. It doesn't have to be a real emailObj address.This could be used for phishing/spoofing! emailObj.setSubject("TestMail"); emailObj.setMsg("This is spring MVC Contact Application sending you the email"); emailObj.addTo(email);//Will come from the sign up details emailObj.send(); } } mv.setViewName("signup"); } return mv; }
From source file:com.jnd.sonar.analysisreport.AnalysisReportHelper.java
public void sendNotificationSMS(String send_sms_to_provider, String send_sms_to, String from, String username, String password, String hostname, String portno, boolean setSSLOnConnectFlag, String subject, String message) {// w w w. j a v a2 s.c om try { send_sms_to_provider = settings.getString(TO_SMS_PROVIDER_PROPERTY); send_sms_to = settings.getString(TO_SMS_PROPERTY); Email smsObject = new SimpleEmail(); DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); Calendar cal = Calendar.getInstance(); String dateStr = dateFormat.format(cal.getTime()); smsObject.setHostName(hostname); smsObject.setSmtpPort(Integer.parseInt(portno)); smsObject.setAuthenticator(new DefaultAuthenticator(username, password)); smsObject.setSSL(true); smsObject.setFrom(from); smsObject.setSubject(""); smsObject.setMsg("Sonar analysis completed successfully at " + dateStr + " . Please visit " + settings.getString("sonar.host.url") + " for more details!"); //multiple SMS recipients. String[] addrs = StringUtils.split(to_email, "\t\r\n;, "); for (String addr : addrs) { smsObject.addTo(send_sms_to); } smsObject.send(); } catch (EmailException e) { throw new SonarException("Unable to send sms", e); } catch (Exception ex) { // TODO Auto-generated catch block ex.printStackTrace(); } }
From source file:fr.gael.dhus.messaging.mail.MailServer.java
public void send(Email email, String to, String cc, String bcc, String subject) throws EmailException { email.setHostName(getSmtpServer());/*from w ww. j a v a 2 s. c om*/ email.setSmtpPort(getPort()); if (getUsername() != null) { email.setAuthentication(getUsername(), getPassword()); } if (getFromMail() != null) { if (getFromName() != null) email.setFrom(getFromMail(), getFromName()); else email.setFrom(getFromMail()); } if (getReplyto() != null) { try { email.setReplyTo(ImmutableList.of(new InternetAddress(getReplyto()))); } catch (AddressException e) { logger.error("Cannot configure Reply-to (" + getReplyto() + ") into the mail: " + e.getMessage()); } } // Message configuration email.setSubject("[" + cfgManager.getNameConfiguration().getShortName() + "] " + subject); email.addTo(to); // Add CCed if (cc != null) { email.addCc(cc); } // Add BCCed if (bcc != null) { email.addBcc(bcc); } email.setStartTLSEnabled(isTls()); try { email.send(); } catch (EmailException e) { logger.error("Cannot send email: " + e.getMessage()); throw e; } }