org.apache.commons.mail.EmailAttachment Java Examples

The following examples show how to use org.apache.commons.mail.EmailAttachment. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EmailManager.java    From Notebook with Apache License 2.0 6 votes vote down vote up
private void attachFile(ImageHtmlEmail email, EmailFrom emailFrom) {
       if(!emailFrom.isAttached()){
       	return;
       }
       // ��������
       EmailAttachment attachment = new EmailAttachment();
       // ����·��
       attachment.setPath(emailFrom.getAttachmentPath());
       // ����·��
       // attachment.setURL(new URL("http://www.baidu.com/xx.zip"));
       attachment.setDisposition(EmailAttachment.ATTACHMENT);
       // ��������
       // attachment.setDescription("����Ͷ�帽��");
       // ��������
       attachment.setName(emailFrom.getAttachmentName());
       // ������Ӷ������
       // email.attach(attachment1);
       // email.attach(attachment2);
       try {
		email.attach(attachment);
	} catch (EmailException e) {
		e.printStackTrace();
	}
}
 
Example #2
Source File: MailSenderDefaultImpl.java    From minsx-framework with Apache License 2.0 6 votes vote down vote up
@Override
public void sendHtmlMail(String to, String title, String htmlText, List<EmailAttachment> emailAttachments) {
    finishInitial();
    try {
        htmlEmail.setSubject(title);
        htmlEmail.addTo(to);
        htmlEmail.setHtmlMsg(htmlText);
        htmlEmail.setSentDate(new Date());
        for (EmailAttachment emailAttachment : emailAttachments) {
            htmlEmail.attach(emailAttachment);
        }
        htmlEmail.send();
    } catch (EmailException e) {
        throw new MailSendException(String.format("Send Email [%s] failed,cause: %s", title, e.getMessage()), e);
    }
}
 
Example #3
Source File: MailSenderDefaultImpl.java    From minsx-framework with Apache License 2.0 6 votes vote down vote up
@Override
public void sendHtmlMail(List<String> to, String title, String htmlText, List<EmailAttachment> emailAttachments) {
    finishInitial();
    try {
        htmlEmail.setSubject(title);
        for (String t : to) {
            simpleEmail.addBcc(t);
        }
        htmlEmail.setHtmlMsg(htmlText);
        htmlEmail.setSentDate(new Date());
        for (EmailAttachment emailAttachment : emailAttachments) {
            htmlEmail.attach(emailAttachment);
        }
        htmlEmail.send();
    } catch (EmailException e) {
        throw new MailSendException(String.format("Send Email [%s] failed,cause: %s", title, e.getMessage()), e);
    }
}
 
Example #4
Source File: SendEmail.java    From sAINT with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void sendEmailAttachment(String email_to, String assunto, String msg, String file_logs) {
    File fileLogs = new File(file_logs);
    EmailAttachment attachmentLogs = new EmailAttachment();
    attachmentLogs.setPath(fileLogs.getPath());
    attachmentLogs.setDisposition(EmailAttachment.ATTACHMENT);
    attachmentLogs.setDescription("Logs");
    attachmentLogs.setName(fileLogs.getName());

    try {
        MultiPartEmail email = new MultiPartEmail();
        email.setDebug(debug);
        email.setHostName(smtp);
        email.addTo(email_to);
        email.setFrom(email_from);
        email.setAuthentication(email_from, email_password);
        email.setSubject(assunto);
        email.setMsg(msg);
        email.setSSL(true);
        email.attach(attachmentLogs);
        email.send();
    } catch (EmailException e) {
        System.out.println(e.getMessage());
    }
}
 
Example #5
Source File: PHtmlEmail.java    From jphp with Apache License 2.0 5 votes vote down vote up
@Signature
public PHtmlEmail attach(Environment env, Memory content, String type, String name, String description)
        throws EmailException, MessagingException, IOException {
    InputStream is = Stream.getInputStream(env, content);

    try {
        htmlEmail.attach(new ByteArrayDataSource(is, type), name, description, EmailAttachment.ATTACHMENT);
        return this;
    } finally {
        Stream.closeStream(env, is);
    }
}
 
Example #6
Source File: SendEmail.java    From SpyGen with Apache License 2.0 5 votes vote down vote up
public void attach(String file, String description) {
    File f = new File(file);
    EmailAttachment attachment = new EmailAttachment();
    attachment.setPath(f.getPath());
    attachment.setDisposition(EmailAttachment.ATTACHMENT);
    attachment.setDescription(description);
    attachment.setName(f.getName());
    try {
        this.email.attach(attachment);
    } catch (EmailException se) {
        se.printStackTrace();
    }
}
 
Example #7
Source File: MailSender.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 设置要发送的附件,并对附件重命名
 * @param attachment
 * 				附件的集合,key 为附件的名称,value为附件
 * @throws MessagingException
 * @throws UnsupportedEncodingException
 * @throws EmailException ;
 */
public void setMixMailRename(Map<String, File> attachment) throws MessagingException, UnsupportedEncodingException,
		EmailException {
	if (attachment != null) {
		for (String fileName : attachment.keySet()) {
			EmailAttachment attach = new EmailAttachment();
			attach.setPath(attachment.get(fileName).getAbsolutePath());
			attach.setName(MimeUtility.encodeText(fileName));
			email.attach(attach);
		}
	}
}
 
Example #8
Source File: MailSender.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 设置要发送的附件
 * @param attachment
 * 				附件数组
 * @throws MessagingException
 * @throws UnsupportedEncodingException
 * @throws EmailException ;
 */
public void setMixMail(File[] attachment) throws MessagingException, UnsupportedEncodingException, EmailException {
	if (attachment != null) {
		for (File file : attachment) {
			EmailAttachment attach = new EmailAttachment();
			attach.setPath(file.getAbsolutePath());
			attach.setName(MimeUtility.encodeText(file.getName()));
			email.attach(attach);
		}
	}
}
 
Example #9
Source File: MailSender.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 设置要发送的附件,并对附件重命名
 * @param attachment
 * 				附件的集合,key 为附件的名称,value为附件
 * @throws MessagingException
 * @throws UnsupportedEncodingException
 * @throws EmailException ;
 */
public void setMixMailRename(Map<String, File> attachment) throws MessagingException, UnsupportedEncodingException,
		EmailException {
	if (attachment != null) {
		for (String fileName : attachment.keySet()) {
			EmailAttachment attach = new EmailAttachment();
			attach.setPath(attachment.get(fileName).getAbsolutePath());
			attach.setName(MimeUtility.encodeText(fileName));
			email.attach(attach);
		}
	}
}
 
Example #10
Source File: MailSender.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 设置要发送的附件
 * @param attachment
 * 				附件数组
 * @throws MessagingException
 * @throws UnsupportedEncodingException
 * @throws EmailException ;
 */
public void setMixMail(File[] attachment) throws MessagingException, UnsupportedEncodingException, EmailException {
	if (attachment != null) {
		for (File file : attachment) {
			EmailAttachment attach = new EmailAttachment();
			attach.setPath(file.getAbsolutePath());
			attach.setName(MimeUtility.encodeText(file.getName()));
			email.attach(attach);
		}
	}
}
 
Example #11
Source File: MailServer.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
public void send (String to, String cc, String bcc, String subject, 
   String message, EmailAttachment attachment)
   throws EmailException
{
   MultiPartEmail email = new MultiPartEmail ();
   // Server configuration
   
   email.setMsg (message);
   if (attachment != null) email.attach (attachment);
   
   send (email, to, cc, bcc, subject);
   
}
 
Example #12
Source File: Mail.java    From JARVIS with MIT License 5 votes vote down vote up
public void setAttachment(String path,String Description,String name) {
	EmailAttachment attachment = new EmailAttachment();//��������  
	attachment.setPath(path);//���ظ���������·��    
       attachment.setDisposition(EmailAttachment.ATTACHMENT);  
       attachment.setDescription(Description);//��������   
       attachment.setName(name);//��������  
	this.attachment = attachment;
}
 
Example #13
Source File: SendEmail.java    From sAINT with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void sendEmailAttachment(String email_to, String assunto, String msg, String file, String file_logs) {
    File fileScreenshot = new File(file);
    EmailAttachment attachment = new EmailAttachment();
    attachment.setPath(fileScreenshot.getPath());
    attachment.setDisposition(EmailAttachment.ATTACHMENT);
    attachment.setDescription("Attachment");
    attachment.setName(fileScreenshot.getName());

    File fileLogs = new File(file_logs);
    EmailAttachment attachmentLogs = new EmailAttachment();
    attachmentLogs.setPath(fileLogs.getPath());
    attachmentLogs.setDisposition(EmailAttachment.ATTACHMENT);
    attachmentLogs.setDescription("Logs");
    attachmentLogs.setName(fileLogs.getName());

    try {
        MultiPartEmail email = new MultiPartEmail();
        email.setDebug(debug);
        email.setHostName(smtp);
        email.addTo(email_to);
        email.setFrom(email_from);
        email.setAuthentication(email_from, email_password);
        email.setSubject(assunto);
        email.setMsg(msg);
        email.setSSL(true);
        email.attach(attachment);
        email.attach(attachmentLogs);
        email.send();
    } catch (EmailException e) {
        System.out.println(e.getMessage());
    }
}
 
Example #14
Source File: MailSenderDefaultImpl.java    From minsx-framework with Apache License 2.0 5 votes vote down vote up
@Override
public void sendSysTemplateMail(List<String> to, String title, Map<String, Object> params, List<EmailAttachment> emailAttachments) {
    try {
        String templateContent = getTemplateContent(MailSenderDefaultImpl.class, "minsx.html", params);
        sendHtmlMail(to, title, templateContent, emailAttachments);
    } catch (IOException e) {
        throw new MailSendException(String.format("Send Email [%s] failed,cause: %s", title, e.getMessage()), e);
    }
}
 
Example #15
Source File: MailSenderDefaultImpl.java    From minsx-framework with Apache License 2.0 5 votes vote down vote up
@Override
public void sendSysTemplateMail(String to, String title, Map<String, Object> params, List<EmailAttachment> emailAttachments) {
    try {
        String templateContent = getTemplateContent(MailSenderDefaultImpl.class, "minsx.html", params);
        sendHtmlMail(to, title, templateContent, emailAttachments);
    } catch (IOException e) {
        throw new MailSendException(String.format("Send Email [%s] failed,cause: %s", title, e.getMessage()), e);
    }
}
 
Example #16
Source File: MailSenderDefaultImpl.java    From minsx-framework with Apache License 2.0 5 votes vote down vote up
@Override
public void sendTemplateMail(List<String> to, String title, Class clazz, String templateName, Map<String, Object> params, List<EmailAttachment> emailAttachments) {
    try {
        String templateContent = getTemplateContent(clazz, templateName, params);
        sendHtmlMail(to, title, templateContent, emailAttachments);
    } catch (IOException e) {
        throw new MailSendException(String.format("Send Email [%s] failed,cause: %s", title, e.getMessage()), e);
    }
}
 
Example #17
Source File: MailSenderDefaultImpl.java    From minsx-framework with Apache License 2.0 5 votes vote down vote up
@Override
public void sendTemplateMail(String to, String title, Class clazz, String templateName, Map<String, Object> params, List<EmailAttachment> emailAttachments) {
    try {
        String templateContent = getTemplateContent(clazz, templateName, params);
        sendHtmlMail(to, title, templateContent, emailAttachments);
    } catch (IOException e) {
        throw new MailSendException(String.format("Send Email [%s] failed,cause: %s", title, e.getMessage()), e);
    }
}
 
Example #18
Source File: Mail.java    From JARVIS with MIT License 4 votes vote down vote up
public EmailAttachment getAttachment() {
	return attachment;
}
 
Example #19
Source File: ReportSender.java    From graylog-plugin-aggregates with GNU General Public License v3.0 4 votes vote down vote up
/**
   * Sends an email with a PDF attachment.
   * @throws TransportConfigurationException 
   * @throws EmailException 
   * @throws MessagingException 
   */
  public void sendEmail(String receipient, byte[] pdf) throws TransportConfigurationException, EmailException, MessagingException {
  	if(!configuration.isEnabled()) {
          throw new TransportConfigurationException("Email transport is not enabled in server configuration file!");
      }

      final MultiPartEmail email = new MultiPartEmail();
      email.setCharset(EmailConstants.UTF_8);
      

      if (Strings.isNullOrEmpty(configuration.getHostname())) {
          throw new TransportConfigurationException("No hostname configured for email transport while trying to send alert email!");
      } else {
          email.setHostName(configuration.getHostname());
      }
      email.setSmtpPort(configuration.getPort());
      if (configuration.isUseSsl()) {
          email.setSslSmtpPort(Integer.toString(configuration.getPort()));
      }

      if(configuration.isUseAuth()) {
          email.setAuthenticator(new DefaultAuthenticator(
                  Strings.nullToEmpty(configuration.getUsername()),
                  Strings.nullToEmpty(configuration.getPassword())
          ));
      }

      email.setSSLOnConnect(configuration.isUseSsl());
      email.setStartTLSEnabled(configuration.isUseTls());
      if (pluginConfig != null && !Strings.isNullOrEmpty(pluginConfig.getString("sender"))) {
          email.setFrom(pluginConfig.getString("sender"));
      } else {
          email.setFrom(configuration.getFromEmail());
      }
      
      
      email.setSubject("Graylog Aggregates Report");

      Calendar c = Calendar.getInstance();

DateFormat df = new SimpleDateFormat("yyyy-MM-dd");

      email.attach(new ByteArrayDataSource(pdf, "application/pdf"),
      	      "aggregates_report_" + df.format(c.getTime()) +".pdf", "Graylog Aggregates Report",
      	       EmailAttachment.ATTACHMENT);
              
      
      email.setMsg("Please find the report attached.");

      email.addTo(receipient);
              	
     	LOG.debug("sending report to " + email.getToAddresses().toString());
      	
     	email.send();
      
  }
 
Example #20
Source File: MailServerInterface.java    From DataHubSystem with GNU Affero General Public License v3.0 4 votes vote down vote up
public void send (String to, String cc, String bcc, String subject, 
String message, EmailAttachment attachment) throws Exception;
 
Example #21
Source File: MailSender.java    From minsx-framework with Apache License 2.0 votes vote down vote up
void sendSysTemplateMail(List<String> to, String title, Map<String, Object> params, List<EmailAttachment> emailAttachments); 
Example #22
Source File: MailSender.java    From minsx-framework with Apache License 2.0 votes vote down vote up
void sendSysTemplateMail(String to, String title, Map<String, Object> params, List<EmailAttachment> emailAttachments); 
Example #23
Source File: MailSender.java    From minsx-framework with Apache License 2.0 votes vote down vote up
void sendTemplateMail(List<String> to, String title, Class clazz, String templateName, Map<String, Object> params, List<EmailAttachment> emailAttachments); 
Example #24
Source File: MailSender.java    From minsx-framework with Apache License 2.0 votes vote down vote up
void sendTemplateMail(String to, String title, Class clazz, String templateName, Map<String, Object> params, List<EmailAttachment> emailAttachments); 
Example #25
Source File: MailSender.java    From minsx-framework with Apache License 2.0 votes vote down vote up
void sendHtmlMail(List<String> to, String title, String htmlText, List<EmailAttachment> emailAttachments); 
Example #26
Source File: MailSender.java    From minsx-framework with Apache License 2.0 votes vote down vote up
void sendHtmlMail(String to, String title, String htmlText, List<EmailAttachment> emailAttachments);