Package org.apache.commons.mail

Examples of org.apache.commons.mail.MultiPartEmail


//                    if (!StringUtils.isEmpty(bodyText)) {
//                        htmlEmail.setTextMsg(bodyText);
//                    }
                    email = htmlEmail;
//                }
                MultiPartEmail multiPartEmail = (MultiPartEmail) email;
                List<EmailAttachment> objectList = (List<EmailAttachment>) infoMap.get(ATTACHMENTS);
                for (EmailAttachment object : objectList) {
                    multiPartEmail.attach(object);
                }
            }

            if (from != null) {
                try {
View Full Code Here


//                    if (!StringUtils.isEmpty(bodyText)) {
//                        htmlEmail.setTextMsg(bodyText);
//                    }
                    email = htmlEmail;
//                }
                MultiPartEmail multiPartEmail = (MultiPartEmail) email;
                List<EmailAttachment> objectList = (List<EmailAttachment>) infoMap.get(ATTACHMENTS);
                for (EmailAttachment object : objectList) {
                    multiPartEmail.attach(object);
                }
            }

            if (from != null) {
                try {
View Full Code Here

//                    if (!StringUtils.isEmpty(bodyText)) {
//                        htmlEmail.setTextMsg(bodyText);
//                    }
                    email = htmlEmail;
//                }
                MultiPartEmail multiPartEmail = (MultiPartEmail) email;
                List<EmailAttachment> objectList = (List<EmailAttachment>) infoMap.get(ATTACHMENTS);
                for (EmailAttachment object : objectList) {
                    multiPartEmail.attach(object);
                }
            }

            if (from != null) {
                try {
View Full Code Here

    }
    return mimetypestemp;
  }

  public void sendMail(EmailDetailsDto emailDto) throws SwingObjectsException{
    MultiPartEmail email=null;
    try {
      if(emailDto.isHtml()) {
        email=new HtmlEmail();
        ((HtmlEmail)email).setHtmlMsg(emailDto.getBody());

      }else {
        email = new MultiPartEmail();
        email.setMsg(emailDto.getBody());
      }
      if (emailDto.getAttachments()!=null) {
        for(Attachments docsDto : emailDto.getAttachments()){
          FileDataSource fd=new FileDataSource(docsDto.getFileLoc());
          fd.setFileTypeMap(mimetypes);
          email.attach(fd, docsDto.getDocName(), docsDto.getDocName());
        }
      }

      setCommonAttributes(emailDto, email);
      email.send();
    }catch(SwingObjectsException e) {
      throw e;
    }catch(EmailException e) {
      if(e.getCause() instanceof AuthenticationFailedException) {
        throw new SwingObjectsException("error.email.authfailed", ErrorSeverity.ERROR, null, EmailHelper.class);
View Full Code Here

   * @param attachments 附件
   */
  public void send( ConnectionConfig conf, MailAddress mailAddress,
      MailContent mail, Attachment[] attachments){
   
    MultiPartEmail email = new MultiPartEmail();   
    fillConfig( email,conf,mailAddress,mail );
       
    try{   
      for( Attachment att: attachments ){     
        email.attach( att.getSource(), att.getName(), att.getDescription() );
      }
      email.send();
    }catch( org.apache.commons.mail.EmailException ee){
      throw new MailException( ee );
    }  
   
  }
View Full Code Here

   */
  public void sendEmail(Email email) throws EmailSendFailedException
  {
    try
    {
      org.apache.commons.mail.Email commonsEmail = email.getAttachmentFileName() != null ? new MultiPartEmail()
              : new SimpleEmail();

      commonsEmail.setDebug(debug);

      commonsEmail.setHostName(email.getMailHost());
View Full Code Here

        attachment.setDisposition(EmailAttachment.ATTACHMENT);
        attachment.setDescription("MoDiHTMLReport");
        attachment.setName("modireport.html");

        // Create the email message
        MultiPartEmail email = new MultiPartEmail();
        email.setHostName(mailhost);
        email.setAuthentication(username, password);
        email.setFrom(fromAddress, "MoDi");

        for (Role role : roles) {
            email.addTo(role.getEmail(), role.getName());
        }

        email.setSubject("[ MoDi ] "
                + Config.getStringProperty("MoDi.Meta.Project.Name"));
       
        email.setMsg(" ");
        email.attach(attachment);
        email.send();

    }
View Full Code Here

        attachment.setDisposition(EmailAttachment.ATTACHMENT);
        attachment.setDescription("MoDiHTMLReport");
        attachment.setName("modireport.html");

        // Create the email message
        MultiPartEmail email = new MultiPartEmail();
        email.setHostName(mailhost);
        email.setAuthentication(username, password);
        email.setFrom(fromAddress, "MoDi");

        for (Role role : roles) {
            email.addTo(role.getEmail(), role.getName());
        }

        email.setSubject("[ MoDi ] "
                + Config.getStringProperty("MoDi.Meta.Project.Name"));
       
        email.setMsg(" ");
        email.attach(attachment);
        email.send();

    }
View Full Code Here

    @Test
    public void testDoPopulateMultipartMailWithContent() throws Exception {

        Mail mail = MailImplTestHelper.getMailImplWithDemoContent();

        MultiPartEmail multiPartEmail = commonsmailHelper.createMultiPartEmailWithContent(mail);
        commonsmailHelper.doPopulateMultipartMailWithContent(multiPartEmail, mail);


        assertTrue(doConvertAdressesToInternetAddressList(multiPartEmail.getBccAddresses())
                .contains(new InternetAddress("bcc1@domain")));

        assertTrue(doConvertAdressesToInternetAddressList(multiPartEmail.getBccAddresses())
                .contains(new InternetAddress("bcc2@domain")));

        assertEquals("subject", multiPartEmail.getSubject());

        assertEquals(new InternetAddress("from1@domain"), multiPartEmail.getFromAddress());

        assertTrue(doConvertAdressesToInternetAddressList(multiPartEmail.getReplyToAddresses())
                .contains(new InternetAddress("replyTo1@domain")));
        assertTrue(doConvertAdressesToInternetAddressList(multiPartEmail.getReplyToAddresses())
                .contains(new InternetAddress("replyTo2@domain")));




        assertTrue(doConvertAdressesToInternetAddressList(multiPartEmail.getCcAddresses())
                .contains(new InternetAddress("cc1@domain")));
        assertTrue(doConvertAdressesToInternetAddressList(multiPartEmail.getCcAddresses())
                .contains(new InternetAddress("cc1@domain")));


        assertTrue(doConvertAdressesToInternetAddressList(multiPartEmail.getBccAddresses())
                .contains(new InternetAddress("bcc1@domain")));
        assertTrue(doConvertAdressesToInternetAddressList(multiPartEmail.getBccAddresses())
                .contains(new InternetAddress("bcc2@domain")));

        assertTrue(doConvertAdressesToInternetAddressList(multiPartEmail.getToAddresses())
                .contains(new InternetAddress("to1@domain")));
        assertTrue(doConvertAdressesToInternetAddressList(multiPartEmail.getToAddresses())
                .contains(new InternetAddress("to2@domain")));

    }
View Full Code Here

    @Test
    public void testDoSetServerParameter() throws Exception {

        Mail mail = MailImplTestHelper.getMailImplWithDemoContent();

        MultiPartEmail multiPartEmail = commonsmailHelper.createMultiPartEmailWithContent(mail);

        commonsmailHelper.doSetServerParameter(
                multiPartEmail,
                "mail.superserver.com",
                33,
                true,
                "username",
                "password",
                true);

        assertEquals("33", multiPartEmail.getSmtpPort());
        assertEquals("mail.superserver.com", multiPartEmail.getHostName());
        assertEquals(true, multiPartEmail.getMailSession().getDebug());


    }
View Full Code Here

TOP

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

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.