List of usage examples for org.apache.commons.mail Email addCc
public Email addCc(final String... emails) throws EmailException
From source file:com.patrolpro.beans.ContactUsBean.java
public String sendEmail() { try {/* w w w . j a va2 s . c om*/ StringBuilder emailMessage = new StringBuilder(); emailMessage.append("From: " + this.name + "\r\n"); emailMessage.append("Email: " + this.email + "\r\n"); emailMessage.append("Phone: " + this.phone + "\r\n"); emailMessage.append(message); Email htmlEmail = new SimpleEmail(); htmlEmail.setMsg(message); htmlEmail.setFrom("contact@patrolpro.com"); htmlEmail.setSubject("Contact Us Email"); htmlEmail.addTo("rharris@ainteractivesolution.com"); htmlEmail.addCc("ijuneau@ainteractivesolution.com"); htmlEmail.addCc("jc@champ.net"); htmlEmail.setMsg(emailMessage.toString()); htmlEmail.setAuthenticator(new MailAuthenticator("schedfox", "Sch3dF0x4m3")); htmlEmail.setHostName("mail2.champ.net"); htmlEmail.setSmtpPort(587); htmlEmail.send(); return "sentContactEmail"; } catch (Exception exe) { } return "invalid"; }
From source file:cl.alma.scrw.bpmn.tasks.MailActivityBehavior.java
protected void addCc(Email email, String cc) { String[] ccs = splitAndTrim(cc); if (ccs != null) { for (String c : ccs) { try { email.addCc(c); } catch (EmailException e) { throw new ActivitiException("Could not add " + c + " as cc recipient", e); }//from w w w.j a v a 2 s .c om } } }
From source file:gov.nih.nci.firebird.service.messages.email.EmailServiceImpl.java
private void addCcAddresses(Email email, Collection<String> cc) throws EmailException { if (cc != null && !cc.isEmpty()) { for (String address : cc) { if (StringUtils.isNotBlank(address)) { email.addCc(address); }/* w w w . ja v a2s. c o m*/ } } }
From source file:com.patrolpro.beans.SignupClientBean.java
public String sendEmail() { try {/*from w ww . j av a2 s . c om*/ 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.ning.billing.util.email.DefaultEmailSender.java
private void sendEmail(final List<String> to, final List<String> cc, final String subject, final Email email) throws EmailApiException { try {// w w w.ja v a 2 s.c o m email.setSmtpPort(config.getSmtpPort()); if (config.useSmtpAuth()) { email.setAuthentication(config.getSmtpUserName(), config.getSmtpPassword()); } email.setHostName(config.getSmtpServerName()); email.setFrom(config.getDefaultFrom()); email.setSubject(subject); if (to != null) { for (final String recipient : to) { email.addTo(recipient); } } if (cc != null) { for (final String recipient : cc) { email.addCc(recipient); } } email.setSSL(config.useSSL()); log.info("Sending email to {}, cc {}, subject {}", new Object[] { to, cc, subject }); email.send(); } catch (EmailException ee) { throw new EmailApiException(ee, ErrorCode.EMAIL_SENDING_FAILED); } }
From source file:com.mirth.connect.server.util.SMTPConnection.java
public void send(String toList, String ccList, String from, String subject, String body) throws EmailException { Email email = new SimpleEmail(); email.setHostName(host);// w w w .j a v a2 s. co m email.setSmtpPort(Integer.parseInt(port)); email.setSocketConnectionTimeout(socketTimeout); email.setDebug(true); if (useAuthentication) { email.setAuthentication(username, password); } if (StringUtils.equalsIgnoreCase(secure, "TLS")) { email.setTLS(true); } else if (StringUtils.equalsIgnoreCase(secure, "SSL")) { email.setSSL(true); } 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:adams.core.net.SimpleApacheSendEmail.java
/** * Sends an email.//from w ww.ja v a 2 s. c o m * * @param email the email to send * @return true if successfully sent * @throws Exception in case of invalid internet addresses or messaging problem */ @Override public boolean sendMail(Email email) throws Exception { org.apache.commons.mail.Email mail; String id; MultiPartEmail mpemail; EmailAttachment attachment; if (email.getAttachments().length > 0) { mail = new MultiPartEmail(); mpemail = (MultiPartEmail) mail; for (File file : email.getAttachments()) { attachment = new EmailAttachment(); attachment.setPath(file.getAbsolutePath()); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setName(file.getName()); mpemail.attach(attachment); } } else { mail = new SimpleEmail(); } mail.setFrom(email.getFrom().getValue()); for (EmailAddress address : email.getTo()) mail.addTo(address.getValue()); for (EmailAddress address : email.getCC()) mail.addCc(address.getValue()); for (EmailAddress address : email.getBCC()) mail.addBcc(address.getValue()); mail.setSubject(email.getSubject()); mail.setMsg(email.getBody()); mail.setHostName(m_Server); mail.setSmtpPort(m_Port); mail.setStartTLSEnabled(m_UseTLS); mail.setSSLOnConnect(m_UseSSL); if (m_RequiresAuth) mail.setAuthentication(m_User, m_Password.getValue()); mail.setSocketTimeout(m_Timeout); try { id = mail.send(); if (isLoggingEnabled()) getLogger().info("Message sent: " + id); } catch (Exception e) { getLogger().log(Level.SEVERE, "Failed to send email: " + mail, e); return false; } return true; }
From source file:com.irurueta.server.commons.email.ApacheMailSender.java
/** * Internal method to send email using Apache Mail. * @param m email message.//from w ww .ja v 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 www. j a v a2 s. 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: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 w w. j a v a 2 s.c o m*/ 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; } }