Package org.apache.commons.mail

Examples of org.apache.commons.mail.SimpleEmail


@Service
public class GmailBackedPlatformEmailService implements PlatformEmailService {

    @Override
    public void sendToUserAccount(final EmailDetail emailDetail, final String unencodedPassword) {
        final Email email = new SimpleEmail();

        final String authuserName = "support@cloudmicrofinance.com";

        final String authuser = "support@cloudmicrofinance.com";
        final String authpwd = "support80";

        // 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");
        try {
            email.getMailSession().getProperties().put("mail.smtp.starttls.enable", "true");
            email.setFrom(authuser, authuserName);

            final StringBuilder subjectBuilder = new StringBuilder().append("MifosX Prototype Demo: ").append(emailDetail.getContactName())
                    .append(" user account creation.");

            email.setSubject(subjectBuilder.toString());

            final String sendToEmail = emailDetail.getAddress();

            final StringBuilder messageBuilder = new StringBuilder().append("You are receiving this email as your email account: ")
                    .append(sendToEmail).append(" has being used to create a user account for an organisation named [")
                    .append(emailDetail.getOrganisationName()).append("] on MifosX Prototype Demo.")
                    .append("You can login using the following credentials: username: ").append(emailDetail.getUsername())
                    .append(" password: ").append(unencodedPassword);

            email.setMsg(messageBuilder.toString());

            email.addTo(sendToEmail, emailDetail.getContactName());
            email.send();
        } catch (final EmailException e) {
            throw new PlatformEmailSendException(e);
        }
    }
View Full Code Here


   */
  public void sendPlain(String from, String to, String cc, String bcc, String bounceAddress, String replyTo, String subject, String content, String encoding) throws SystemException
  {
    try
    {
        SimpleEmail email = new SimpleEmail();
        String mailServer = CmsPropertyHandler.getMailSmtpHost();
        String mailPort = CmsPropertyHandler.getMailSmtpPort();
        String systemEmailSender = CmsPropertyHandler.getSystemEmailSender();
       
        email.setHostName(mailServer);
        if(mailPort != null && !mailPort.equals(""))
          email.setSmtpPort(Integer.parseInt(mailPort));
       
        boolean needsAuthentication = false;
        try
        {
        needsAuthentication = new Boolean(CmsPropertyHandler.getMailSmtpAuth()).booleanValue();
        }
        catch (Exception ex)
        {
        needsAuthentication = false;
        }
       
        if (needsAuthentication)
        {
        final String userName = CmsPropertyHandler.getMailSmtpUser();
        final String password = CmsPropertyHandler.getMailSmtpPassword();
       
        email.setAuthentication(userName, password);
      }
       
        email.setBounceAddress(systemEmailSender);
        email.setCharset(encoding);
      
        if(to.indexOf(";") > -1)
        {
          cc = to;
          to = from;
        }

        String limitString = CmsPropertyHandler.getEmailRecipientLimit();
        if(limitString != null && !limitString.equals("-1"))
        {
          try
          {
            Integer limit = new Integer(limitString);
            int count = 0;
            if(cc != null)
              count = count + cc.split(";").length;
            if(bcc != null)
              count = count + bcc.split(";").length;
           
            logger.info("limit: " + limit + ", count: " + count);
            if(count > limit)
              throw new Exception("You are not allowed to send mail to more than " + limit + " recipients at a time. This is specified in app settings.");
          }
          catch (NumberFormatException e)
          {
            logger.error("Exception validating number of recipients in mailservice:" + e.getMessage(), e);
        }
        }

        email.addTo(to, to);
        email.setFrom(from, from);
       
        if(cc != null)
          email.setCc(createInternetAddressesList(cc));
        if(bcc != null)
          email.setBcc(createInternetAddressesList(bcc));
        if(replyTo != null)
          email.setReplyTo(createInternetAddressesList(replyTo));
       
        email.setSubject(subject);
        email.setMsg(content);
 
        email.send();
    }
      catch (Exception e)
      {
        logger.error("An error occurred when we tried to send this mail:" + e.getMessage(), e);
      }
View Full Code Here

      throw new ActivitiException("Could not create HTML email", e);
    }
  }

  protected SimpleEmail createTextOnlyEmail(String text) {
    SimpleEmail email = new SimpleEmail();
    try {
      email.setMsg(text);
      return email;
    } catch (EmailException e) {
      throw new ActivitiException("Could not create text-only email", e);
    }
  }
View Full Code Here

      @ParamDoc(name="subject") String subject,
      @ParamDoc(name="message") String message,
      @ParamDoc(name="attachmentUrl") String attachmentUrl) {
    boolean success = false;
    if(MailActionService.isProperlyConfigured) {
      Email email = new SimpleEmail();
      if(attachmentUrl!=null) {
        // Create the attachment
          try {
            email = new MultiPartEmail();
            EmailAttachment attachment = new EmailAttachment();
            attachment.setURL(new URL(attachmentUrl));
            attachment.setDisposition(EmailAttachment.ATTACHMENT);
            attachment.setName("Attachment");
            ((MultiPartEmail) email).attach(attachment);
        } catch (MalformedURLException e) {
          logger.error("Invalid attachment url.", e);
        } catch (EmailException e) {
          logger.error("Error adding attachment to email.", e);
        }
      }

      email.setHostName(hostname);
      email.setSmtpPort(port);
      email.setTLS(tls);
     
      if (StringUtils.isNotBlank(username)) {
        if (popBeforeSmtp) {
          email.setPopBeforeSmtp(true, hostname, username, password);
        } else {
          email.setAuthenticator(new DefaultAuthenticator(username, password));
        }
      }

      try {
        email.setFrom(from);
        email.addTo(to);
        if(!StringUtils.isEmpty(subject)) email.setSubject(subject);
        if(!StringUtils.isEmpty(message)) email.setMsg(message);
        email.send();
        logger.debug("Sent email to '{}' with subject '{}'.", to, subject);
        success = true;
      } catch (EmailException e) {
        logger.error("Could not send e-mail to '" + to + "‘.", e);
      }
View Full Code Here

        this.nome = nome;
    }
   
    public void enviarEmail(){
        try {
            SimpleEmail mailer = new SimpleEmail();
            mailer.setHostName(configuracao.getConSmtpServer());
            mailer.addTo(siteMB.getBean().getSitEmailContato());
            mailer.setFrom(email, nome);
            mailer.setSubject(assunto);
            mailer.setMsg(mensagem);
            mailer.setAuthentication(configuracao.getConSmtpUser(), configuracao.getConSmtpPassword());
           
            //configuracao gmailç
            mailer.setSmtpPort(465)
            mailer.setSSL(true)
            mailer.setTLS(true)

            mailer.send();
           
            messageContext.add("Contato realizado com sucesso.", SeverityType.INFO);
        } catch (EmailException ex) {
            messageContext.add("Erro ao Enviar E-mail", SeverityType.ERROR);
            Logger.getLogger(ContatoSiteMB.class.getName()).log(Level.SEVERE, null, ex);
View Full Code Here

TOP

Related Classes of org.apache.commons.mail.SimpleEmail

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.