当前位置: 首页>>代码示例>>Java>>正文


Java MultiPartEmail类代码示例

本文整理汇总了Java中org.apache.commons.mail.MultiPartEmail的典型用法代码示例。如果您正苦于以下问题:Java MultiPartEmail类的具体用法?Java MultiPartEmail怎么用?Java MultiPartEmail使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MultiPartEmail类属于org.apache.commons.mail包,在下文中一共展示了MultiPartEmail类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendEmailAttachment

import org.apache.commons.mail.MultiPartEmail; //导入依赖的package包/类
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());
    }
}
 
开发者ID:tiagorlampert,项目名称:sAINT,代码行数:25,代码来源:SendEmail.java

示例2: fillEmail

import org.apache.commons.mail.MultiPartEmail; //导入依赖的package包/类
/**
 * Fill email.
 *
 * @param email
 *            the email
 * @throws EmailException
 *             the email exception
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public void fillEmail(final MultiPartEmail email) throws EmailException, IOException {
	email.setHostName(getHost());
	email.setSmtpPort(getSmtpPort());
	
	email.addTo(getTo());
	email.setFrom(getFrom());
	email.setSubject(getSubject());
	email.setMsg(getMsg());
	email.setSSLOnConnect(isSecured());
	if (isRequiresAuthentication()) {
		email.setAuthentication(getUsername(), getPassword());
	}
	for (int i = 0; i < this.attachements.size(); i++) {
		final Attachment attachment = this.attachements.get(i);
		final ByteArrayDataSource ds = new ByteArrayDataSource(attachment.getData(), attachment.getMimeType());
		email.attach(ds, attachment.getName(), attachment.getDescription());
	}
}
 
开发者ID:kiswanij,项目名称:jk-util,代码行数:29,代码来源:MailInfo.java

示例3: newMail

import org.apache.commons.mail.MultiPartEmail; //导入依赖的package包/类
public MultiPartEmail newMail() {
    MultiPartEmail mail = new MultiPartEmail();

    mail.setHostName(host);
    if (!ssl)
        mail.setSmtpPort(port);
    else
        mail.setSslSmtpPort(valueOf(port));
    if (username != null && password != null)
        mail.setAuthentication(username, password);

    try {
        if (fromMail != null)
            mail.setFrom(fromMail);
    } catch (EmailException e) {
        throw new RuntimeException(e);
    }

    return mail;
}
 
开发者ID:kantega,项目名称:respiro,代码行数:21,代码来源:ServerConfig.java

示例4: includeAttachments

import org.apache.commons.mail.MultiPartEmail; //导入依赖的package包/类
private void includeAttachments(List<LabelValueBean> attachments) throws Exception {
	for (int i = 0; i < attachments.size(); i++) {
		LabelValueBean lvb=attachments.get(i);
		String fullFileName=lvb.getValue();
		String fileName=lvb.getLabel();
		File f=new File(fullFileName);
		if(f!=null&&f.exists()){
			LOGGER.debug("Use attachment file:"+f.getAbsolutePath());
			org.apache.commons.mail.EmailAttachment attachment = new org.apache.commons.mail.EmailAttachment();
			attachment.setPath(f.getAbsolutePath());
			attachment.setName(fileName);
			attachment.setDisposition(org.apache.commons.mail.EmailAttachment.ATTACHMENT);
			((MultiPartEmail) email).attach(attachment);
		}else{
			LOGGER.debug("Attachment file \"" + lvb.getValue() + "\" does not not exist!");
		}
	}
}
 
开发者ID:trackplus,项目名称:Genji,代码行数:19,代码来源:MailSender.java

示例5: prepareAndSend

import org.apache.commons.mail.MultiPartEmail; //导入依赖的package包/类
/**
 * Prepare and send filejackets to the specified email address.
 * <p>
 * @param fileJackets files to be send
 */
private void prepareAndSend(List<FileJacket> fileJackets) {
    SubMonitor m = monitorFactory.newSubMonitor("Transfer");
    m.message("sending Mail");
    m.start();

    try {
        ListingMailConfiguration config = listingService.get().listingMailConfiguration();

        MultiPartEmail email = mandator.prepareDirectMail();
        email.setFrom(config.getFromAddress());
        email.addTo(config.getToAddress());
        email.setSubject(config.getSubject());
        email.setMsg(config.toMessage());

        for (FileJacket fj : fileJackets) {
            email.attach(
                    new javax.mail.util.ByteArrayDataSource(fj.getContent(), "application/xls"),
                    fj.getHead() + fj.getSuffix(), "Die Händlerliste für die Marke ");
        }

        email.send();
        m.finish();
    } catch (EmailException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:gg-net,项目名称:dwoss,代码行数:32,代码来源:SalesListingProducerOperation.java

示例6: configure

import org.apache.commons.mail.MultiPartEmail; //导入依赖的package包/类
@Override
public void configure(final Env env, final Config config, final Binder binder) {
  Config mail = config.getConfig(name).withFallback(config.getConfig("mail"));

  ServiceKey serviceKey = env.serviceKey();
  serviceKey.generate(SimpleEmail.class, name, k -> {
    binder.bind(k).toProvider(new SimpleEmailProvider(mail));
  });
  serviceKey.generate(HtmlEmail.class, name, k -> {
    binder.bind(k).toProvider(new HtmlEmailProvider(mail));
  });
  serviceKey.generate(MultiPartEmail.class, name, k -> {
    binder.bind(k).toProvider(new MultiPartEmailProvider(mail));
  });
  serviceKey.generate(ImageHtmlEmail.class, name, k -> {
    binder.bind(k).toProvider(new ImageHtmlEmailProvider(mail));
  });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:19,代码来源:CommonsEmail.java

示例7: send

import org.apache.commons.mail.MultiPartEmail; //导入依赖的package包/类
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);
   
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:14,代码来源:MailServer.java

示例8: main

import org.apache.commons.mail.MultiPartEmail; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    Email email = new SimpleEmail();
    email.setHostName("smtp.googlemail.com");
    email.setSSLOnConnect(false); //OK

    Email email2 = new SimpleEmail();
    email2.setHostName("smtp2.googlemail.com");        
    email2.setSSLOnConnect(true); //BAD
    //email2.setSmtpPort(465);
    //email2.setAuthenticator(new DefaultAuthenticator("username", "password"));
    //email2.setFrom("[email protected]");
    //email2.setSubject("TestMail");
    //email2.setMsg("This is a test mail ... :-)");
    //email2.addTo("[email protected]");
    //email2.send();

    MultiPartEmail emailMulti = new MultiPartEmail();
    emailMulti.setHostName("mail.myserver.com");
    emailMulti.setSSLOnConnect(true); //BAD

    HtmlEmail htmlEmail = new HtmlEmail();
    htmlEmail.setHostName("mail.myserver.com");
    htmlEmail.setSSLOnConnect(true); //BAD

    ImageHtmlEmail imageEmail = new ImageHtmlEmail();
    imageEmail.setHostName("mail.myserver.com");
    imageEmail.setSSLOnConnect(true);
    imageEmail.setSSLCheckServerIdentity(true); //OK
    
    ImageHtmlEmail imageEmail2 = new ImageHtmlEmail();
    imageEmail2.setHostName("mail2.myserver.com");
    imageEmail2.setSSLCheckServerIdentity(true); //OK - reversed order
    imageEmail2.setSSLOnConnect(true);

    ImageHtmlEmail imageEmail3 = new ImageHtmlEmail();
    imageEmail3.setHostName("mail3.myserver.com");
    imageEmail3.setSSLOnConnect(true); //BAD
}
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:39,代码来源:InsecureSmtpSsl.java

示例9: createMultiPartEmail

import org.apache.commons.mail.MultiPartEmail; //导入依赖的package包/类
protected MultiPartEmail createMultiPartEmail(String text) {
    MultiPartEmail email = new MultiPartEmail();
    try {
        email.setMsg(text);
        return email;
    } catch (EmailException e) {
        throw new FlowableException("Could not create text-only email", e);
    }
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:10,代码来源:MailActivityBehavior.java

示例10: attach

import org.apache.commons.mail.MultiPartEmail; //导入依赖的package包/类
protected void attach(Email email, List<File> files, List<DataSource> dataSources) throws EmailException {
    if (!(email instanceof MultiPartEmail && attachmentsExist(files, dataSources))) {
        return;
    }
    MultiPartEmail mpEmail = (MultiPartEmail) email;
    for (File file : files) {
        mpEmail.attach(file);
    }
    for (DataSource ds : dataSources) {
        if (ds != null) {
            mpEmail.attach(ds, ds.getName(), null);
        }
    }
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:15,代码来源:MailActivityBehavior.java

示例11: createMultiPartEmail

import org.apache.commons.mail.MultiPartEmail; //导入依赖的package包/类
protected MultiPartEmail createMultiPartEmail(String text) {
    MultiPartEmail email = new MultiPartEmail();
    try {
        email.setMsg(text);
        return email;
    } catch (EmailException e) {
        throw new ActivitiException("Could not create text-only email", e);
    }
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:10,代码来源:MailActivityBehavior.java

示例12: buildContent

import org.apache.commons.mail.MultiPartEmail; //导入依赖的package包/类
/**
 * Builds email content to be sent using an email sender.
 * @param content instance where content must be set.
 * @throws com.irurueta.server.commons.email.EmailException if setting mail 
 * content fails.
 */
@Override
protected void buildContent(MultiPartEmail content) 
        throws com.irurueta.server.commons.email.EmailException {
    try {            
        content.setMsg(getText());
    } catch (EmailException e) {
        throw new com.irurueta.server.commons.email.EmailException(e);
    }
}
 
开发者ID:albertoirurueta,项目名称:irurueta-server-commons-email,代码行数:16,代码来源:ApacheMailTextEmailMessage.java

示例13: sendMultiPartEmail

import org.apache.commons.mail.MultiPartEmail; //导入依赖的package包/类
/**
 * Method to send a multipart email.
 * @param m email message to be sent.
 * @return id of message that has been sent.
 * @throws MailNotSentException if mail couldn't be sent.
 */        
public String sendMultiPartEmail(EmailMessage<MultiPartEmail> m) 
        throws MailNotSentException {
    try {
        MultiPartEmail email = new MultiPartEmail();
        internalSendApacheEmail(m, email);
    } catch (Throwable t) {
        throw new MailNotSentException(t);
    }
    return null;
}
 
开发者ID:albertoirurueta,项目名称:irurueta-server-commons-email,代码行数:17,代码来源:ApacheMailSender.java

示例14: buildContent

import org.apache.commons.mail.MultiPartEmail; //导入依赖的package包/类
/**
 * Builds email content to be sent using an email sender.
 * @param content instance where content must be set.
 * @throws com.irurueta.server.commons.email.EmailException if setting mail 
 * content fails.
 */        
@Override
protected void buildContent(MultiPartEmail content) 
        throws com.irurueta.server.commons.email.EmailException {
    try {
        if (getText() != null) {
            content.setMsg(getText());
        }
                    
        //add attachments
        List<EmailAttachment> attachments = getAttachments();
        org.apache.commons.mail.EmailAttachment apacheAttachment;
        if (attachments != null) {
            for (EmailAttachment attachment : attachments) {
                //only add attachments with files
                if (attachment.getAttachment() == null) {
                    continue;
                }
                
                apacheAttachment = new  org.apache.commons.mail.
                        EmailAttachment();
                apacheAttachment.setPath(attachment.getAttachment().getAbsolutePath());
                apacheAttachment.setDisposition(
                        org.apache.commons.mail.EmailAttachment.ATTACHMENT);
                if (attachment.getName() != null) {
                    apacheAttachment.setName(attachment.getName());
                }
                
                content.attach(apacheAttachment);
            }
        }
    } catch (EmailException e) {
        throw new com.irurueta.server.commons.email.EmailException(e);
    }
}
 
开发者ID:albertoirurueta,项目名称:irurueta-server-commons-email,代码行数:41,代码来源:ApacheMailTextEmailMessageWithAttachments.java

示例15: send

import org.apache.commons.mail.MultiPartEmail; //导入依赖的package包/类
@Override
public String send(Message msg) {

    // See: http://stackoverflow.com/questions/21856211/javax-activation-unsupporteddatatypeexception-no-object-dch-for-mime-type-multi
    currentThread().setContextClassLoader(getClass().getClassLoader());

    MultiPartEmail mail = config.newMail();

    try {
        mail.setCharset(msg.getCharset().name());
        addAddresses(mail.getToAddresses(), msg.getTo());
        addAddresses(mail.getCcAddresses(), msg.getCc());
        addAddresses(mail.getBccAddresses(), msg.getBcc());
        addAttachments(mail, msg);
        if (msg.getFrom() != null)
            mail.setFrom(msg.getFrom());
        
        mail.setSubject(msg.getSubject());
        mail.setMsg(msg.getBody());
        if (mail.getToAddresses().size() + mail.getCcAddresses().size() + mail.getBccAddresses().size() > 0)
            return mail.send();
        else
            return "Mail not sent due to empty recipiants list.";
    } catch (EmailException | AddressException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:kantega,项目名称:respiro,代码行数:28,代码来源:SMTPMailSender.java


注:本文中的org.apache.commons.mail.MultiPartEmail类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。