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


Java BodyPart.setText方法代码示例

本文整理汇总了Java中javax.mail.BodyPart.setText方法的典型用法代码示例。如果您正苦于以下问题:Java BodyPart.setText方法的具体用法?Java BodyPart.setText怎么用?Java BodyPart.setText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.mail.BodyPart的用法示例。


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

示例1: getMessagePart

import javax.mail.BodyPart; //导入方法依赖的package包/类
private static Multipart getMessagePart() throws MessagingException, IOException {
    Multipart multipart = new MimeMultipart();
    BodyPart messageBodyPart = new MimeBodyPart();
    messageBodyPart.setText(getVal("msg.Body"));
    multipart.addBodyPart(messageBodyPart);
    if (getBoolVal("attach.reports")) {
        LOG.info("Attaching Reports as zip");
        multipart.addBodyPart(getReportsBodyPart());
    } else {
        if (getBoolVal("attach.standaloneHtml")) {
            multipart.addBodyPart(getStandaloneHtmlBodyPart());
        }
        if (getBoolVal("attach.console")) {
            multipart.addBodyPart(getConsoleBodyPart());
        }
        if (getBoolVal("attach.screenshots")) {
            multipart.addBodyPart(getScreenShotsBodyPart());
        }
    }
    messageBodyPart.setContent(getVal("msg.Body")
            .concat("\n\n\n")
            .concat(MailComponent.getHTMLBody()), "text/html");
    return multipart;
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:25,代码来源:Mailer.java

示例2: buildMessage

import javax.mail.BodyPart; //导入方法依赖的package包/类
private static Message buildMessage(Session session, String from, String recipients, String subject, String text, String filename) throws MessagingException, AddressException
{
    Message message = new MimeMessage(session);
    message.setFrom(new InternetAddress(from));
    message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients));
    message.setSubject(subject);

    BodyPart messageTextPart = new MimeBodyPart();
    messageTextPart.setText(text);

    BodyPart messageAttachmentPart = new MimeBodyPart();
    DataSource source = new FileDataSource(new File(filename));
    messageAttachmentPart.setDataHandler(new DataHandler(source));
    messageAttachmentPart.setFileName(filename);

    Multipart multipart = new MimeMultipart();
    multipart.addBodyPart(messageTextPart);
    multipart.addBodyPart(messageAttachmentPart);
    message.setContent(multipart);

    return message;
}
 
开发者ID:marcelovca90,项目名称:anti-spam-weka-gui,代码行数:23,代码来源:MailHelper.java

示例3: createMultiPart

import javax.mail.BodyPart; //导入方法依赖的package包/类
/**
 * 创建复杂的正文
 * @return
 * @throws MessagingException 
 */
private Multipart createMultiPart() throws MessagingException {
	// TODO Auto-generated method stub
	Multipart multipart=new MimeMultipart();
	
	//第一块
	BodyPart bodyPart1=new MimeBodyPart();
	bodyPart1.setText("创建复杂的邮件,此为正文部分");
	multipart.addBodyPart(bodyPart1);
	
	//第二块 以附件形式存在
	MimeBodyPart bodyPart2=new MimeBodyPart();
	//设置附件的处理器
	FileDataSource attachFile=new FileDataSource(ClassLoader.getSystemResource("attach.txt").getFile());
	DataHandler dh=new DataHandler(attachFile);
	bodyPart2.setDataHandler(dh);
	bodyPart2.setDisposition(Part.ATTACHMENT);
	bodyPart2.setFileName("test");
	multipart.addBodyPart(bodyPart2);
	
	return multipart;
}
 
开发者ID:xiaomin0322,项目名称:alimama,代码行数:27,代码来源:SimpleSendReceiveMessage.java

示例4: prepareMessage

import javax.mail.BodyPart; //导入方法依赖的package包/类
/**
 * @param attachmentPaths
 *            Paths to attachment files.
 * @throws Exception
 *             Exception.
 * @return Message with attachments.
 */
private Message prepareMessage(String[] attachmentPaths) throws Exception {
    Message message = new MimeMessage(Session.getDefaultInstance(System.getProperties()));
    BodyPart messageBodyPart = new MimeBodyPart();
    messageBodyPart.setText("Test.");
    Multipart multipart = new MimeMultipart();
    multipart.addBodyPart(messageBodyPart);
    for (String file : attachmentPaths) {
        BodyPart attachmentPart = new MimeBodyPart();
        File attachment = new File(SRC_TEST_RESOURCES_MAILING_TEST + "/" + file);
        DataSource source = new FileDataSource(attachment);
        attachmentPart.setDataHandler(new DataHandler(source));
        attachmentPart.setFileName(attachment.getName());
        multipart.addBodyPart(attachmentPart);
    }
    message.setContent(multipart);
    message.removeHeader("Content-Type");
    message.setHeader("Content-Type", "multipart/mixed");
    Assert.assertTrue(message.isMimeType("multipart/*"));
    return message;
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:28,代码来源:MailMessageHelperTest.java

示例5: sendKindleMail

import javax.mail.BodyPart; //导入方法依赖的package包/类
private void sendKindleMail(AppUser user, byte[] attachment, String filename) throws MessagingException {
    BodyPart messageBodyPart = new MimeBodyPart();
    messageBodyPart.setText("Bookery delivery, frei haus!");

    BodyPart attachmentPart = new MimeBodyPart();
    attachmentPart.setFileName(filename + ".mobi");
    attachmentPart.setContent(attachment, "application/octet-stream");
    //attachmentPart.setDataHandler(new DataHandler(new ByteArrayDataSource(attachment, "application/x-mobipocket-ebook")));

    Multipart multipart = new MimeMultipart();
    multipart.addBodyPart(messageBodyPart);
    multipart.addBodyPart(attachmentPart);

    MimeMessage message = new MimeMessage(mailSession);
    InternetAddress[] address = {new InternetAddress(user.geteMail())};
    message.setRecipients(Message.RecipientType.TO, address);
    message.setSubject("Bookery delivery");
    message.setSentDate(new Date());
    message.setContent(multipart);

    Transport.send(message);
}
 
开发者ID:felixhusse,项目名称:bookery,代码行数:23,代码来源:BookeryMailService.java

示例6: messageMultipart

import javax.mail.BodyPart; //导入方法依赖的package包/类
public static Multipart messageMultipart(List<File> listOfFlies) throws MessagingException {

        // BodyPart to hold message body
        BodyPart messageBody = new MimeBodyPart();
        // Now set the actual message
        messageBody.setText("Hello, this is sample email with attachments to check/send "
                + "email using JavaMailAPI from "+ ConfigConsts.SMPT_HOST_NAME);

        // Multipart will hold messageBodyPart and attachments
        Multipart multipart = new MimeMultipart();

        // Add Message BodyPart to Multipart
        multipart.addBodyPart(messageBody);

        // Add Files to multipart
        addFileToMultipart(listOfFlies, multipart);

        return multipart;
    }
 
开发者ID:RawSanj,项目名称:java-mail-clients,代码行数:20,代码来源:MailMessageUtils.java

示例7: send

import javax.mail.BodyPart; //导入方法依赖的package包/类
public boolean send() throws MessagingException {
    if(!user.equals("") && !pass.equals("") && !to.equals("")  && !from.equals("")) {
        Session session = Session.getDefaultInstance(props, this);
        Log.d("SendUtil", host + "..." + port + ".." + user + "..." + pass);

        MimeMessage msg = new MimeMessage(session);

        msg.setFrom(new InternetAddress(from));

        InternetAddress addressTo = new InternetAddress(to);
        msg.setRecipient(MimeMessage.RecipientType.TO, addressTo);

        msg.setSubject(subject);
        msg.setSentDate(new Date());

        // setup message body
        BodyPart messageBodyPart = new MimeBodyPart();
        messageBodyPart.setText(body);
        multipart.addBodyPart(messageBodyPart);

        // Put parts in message
        msg.setContent(multipart);

        // send email
        Transport.send(msg);

        return true;
    } else {
        return false;
    }
}
 
开发者ID:msdx,项目名称:SuperLog,代码行数:32,代码来源:LogMail.java

示例8: send

import javax.mail.BodyPart; //导入方法依赖的package包/类
public boolean send() throws Exception { 
	Properties props = _setProperties(); 

	if(!_user.equals("") && !_pass.equals("") && _to.length > 0 && !_from.equals("") && !_subject.equals("") && !_body.equals("")) { 
		Session session = Session.getInstance(props, this); 

		MimeMessage msg = new MimeMessage(session); 

		msg.setFrom(new InternetAddress(_from)); 

		InternetAddress[] addressTo = new InternetAddress[_to.length]; 
		for (int i = 0; i < _to.length; i++) { 
			addressTo[i] = new InternetAddress(_to[i]); 
		} 
		msg.setRecipients(MimeMessage.RecipientType.TO, addressTo); 

		msg.setSubject(_subject); 
		msg.setSentDate(new Date()); 

		// setup message body 
		BodyPart messageBodyPart = new MimeBodyPart(); 
		messageBodyPart.setText(_body); 
		_multipart.addBodyPart(messageBodyPart); 

		// Put parts in message 
		msg.setContent(_multipart); 

		// send email 
		Transport.send(msg); 

		return true; 
	} else { 
		return false; 
	} 
}
 
开发者ID:occc-ir,项目名称:cloud_android_client,代码行数:36,代码来源:Mail.java

示例9: send

import javax.mail.BodyPart; //导入方法依赖的package包/类
public boolean send() throws Exception { 
  Properties props = _setProperties(); 
 
  if(!_user.equals("") && !_pass.equals("") && _to.length > 0 && !_from.equals("") && !_subject.equals("") && !_body.equals("")) { 
    Session session = Session.getInstance(props, this); 
 
    MimeMessage msg = new MimeMessage(session); 
 
    msg.setFrom(new InternetAddress(_from)); 
     
    InternetAddress[] addressTo = new InternetAddress[_to.length]; 
    for (int i = 0; i < _to.length; i++) { 
      addressTo[i] = new InternetAddress(_to[i]); 
    } 
      msg.setRecipients(MimeMessage.RecipientType.TO, addressTo); 
 
    msg.setSubject(_subject); 
    msg.setSentDate(new Date()); 
 
    // setup message body 
    BodyPart messageBodyPart = new MimeBodyPart(); 
    messageBodyPart.setText(_body); 
    _multipart.addBodyPart(messageBodyPart); 
 
    // Put parts in message 
    msg.setContent(_multipart); 
 
    // send email 
    Transport.send(msg); 
 
    return true; 
  } else { 
    return false; 
  } 
}
 
开发者ID:thisisdhaas,项目名称:CookEase,代码行数:36,代码来源:Mail.java

示例10: send

import javax.mail.BodyPart; //导入方法依赖的package包/类
public boolean send() throws Exception 
{ 
  Properties props = setProperties(); 

  if(!user.equals("") && !pass.equals("") && to.length > 0 && !from.equals("") && !subject.equals("") && !body.equals("")) 
  { 
    Session session = Session.getInstance(props, this); 

    MimeMessage msg = new MimeMessage(session); 

    msg.setFrom(new InternetAddress(from)); 

    InternetAddress[] addressTo = new InternetAddress[to.length]; 
    for (int i = 0; i < to.length; i++) 
    { 
      addressTo[i] = new InternetAddress(to[i]); 
    } 
      msg.setRecipients(MimeMessage.RecipientType.TO, addressTo); 

    msg.setSubject(subject); 
    msg.setSentDate(new Date()); 

    // setup message body 
    BodyPart messageBodyPart = new MimeBodyPart(); 
    messageBodyPart.setText(body); 
    multipart.addBodyPart(messageBodyPart); 

    // Put parts in message 
    msg.setContent(multipart); 

    // send email 
    Transport.send(msg); 

    return true; 
  } else 
  { 
    return false; 
  } 
}
 
开发者ID:vocefiscal,项目名称:vocefiscal-android,代码行数:40,代码来源:GMailSender.java

示例11: addAttachment

import javax.mail.BodyPart; //导入方法依赖的package包/类
public void addAttachment(String filename,String subject) throws Exception { 
    BodyPart messageBodyPart = new MimeBodyPart(); 
    DataSource source = new FileDataSource(filename); 
    messageBodyPart.setDataHandler(new DataHandler(source)); 
    messageBodyPart.setFileName(filename.substring(filename.lastIndexOf("/") + 1)); 
    multipart.addBodyPart(messageBodyPart);

    BodyPart messageBodyPart2 = new MimeBodyPart(); 
    messageBodyPart2.setText(subject); 

    multipart.addBodyPart(messageBodyPart2); 
}
 
开发者ID:ManuKothari,项目名称:KeepSafe,代码行数:13,代码来源:GmailSender.java

示例12: testAttachments

import javax.mail.BodyPart; //导入方法依赖的package包/类
@Test
public void testAttachments() throws Exception{

        Map<String, Object> settings = settings("/river-imap-attachments.json");

	final Properties props = new Properties();
	final String user = XContentMapValues.nodeStringValue(settings.get("user"), null);
	final String password = XContentMapValues.nodeStringValue(settings.get("password"), null);

	for (final Map.Entry<String, Object> entry : settings.entrySet()) {

		if (entry != null && entry.getKey().startsWith("mail.")) {
			props.setProperty(entry.getKey(), String.valueOf(entry.getValue()));
		}
	}

	registerRiver("imap_river", "river-imap-attachments.json");

	final Session session = Session.getInstance(props);
	final Store store = session.getStore();
	store.connect(user, password);
	checkStoreForTestConnection(store);
	final Folder inbox = store.getFolder("INBOX");
	inbox.open(Folder.READ_WRITE);



	final MimeMessage message = new MimeMessage(session);
	message.setFrom(new InternetAddress(EMAIL_TO));
	message.addRecipient(Message.RecipientType.TO, new InternetAddress(EMAIL_USER_ADDRESS));
	message.setSubject(EMAIL_SUBJECT + "::attachment test");
	message.setSentDate(new Date());

	BodyPart bp = new MimeBodyPart();
	bp.setText("Text");
	Multipart mp = new MimeMultipart();
	mp.addBodyPart(bp);

	bp = new MimeBodyPart();
	DataSource ds = new ByteArrayDataSource(this.getClass().getResourceAsStream("/httpclient-tutorial.pdf"), AttachmentMapperTest.APPLICATION_PDF);
	bp.setDataHandler(new DataHandler(ds));
	bp.setFileName("httpclient-tutorial.pdf");
	mp.addBodyPart(bp);
	message.setContent(mp);

	inbox.appendMessages(new Message[]{message});
	IMAPUtils.close(inbox);
	IMAPUtils.close(store);

	//let the river index
	Thread.sleep(20*1000);

	esSetup.client().admin().indices().refresh(new RefreshRequest()).actionGet();

	SearchResponse searchResponse =  esSetup.client().prepareSearch("imapriverdata").setTypes("mail").execute().actionGet();
	Assert.assertEquals(1, searchResponse.getHits().totalHits());
               
	//BASE64 content httpclient-tutorial.pdf
	Assert.assertTrue(searchResponse.getHits().hits()[0].getSourceAsString().contains(AttachmentMapperTest.PDF_BASE64_DETECTION));

	searchResponse =  esSetup.client().prepareSearch("imapriverdata").addFields("*").setTypes("mail").setQuery(QueryBuilders.matchPhraseQuery("attachments.content.content", PDF_CONTENT_TO_SEARCH)).execute().actionGet();
	Assert.assertEquals(1, searchResponse.getHits().totalHits());

	Assert.assertEquals(1, searchResponse.getHits().hits()[0].field("attachments.content.content").getValues().size());
	Assert.assertEquals("HttpClient Tutorial", searchResponse.getHits().hits()[0].field("attachments.content.title").getValue().toString());
	Assert.assertEquals("application/pdf", searchResponse.getHits().hits()[0].field("attachments.content.content_type").getValue().toString());
	Assert.assertTrue(searchResponse.getHits().hits()[0].field("attachments.content.content").getValue().toString().contains(PDF_CONTENT_TO_SEARCH));

}
 
开发者ID:salyh,项目名称:elasticsearch-imap,代码行数:70,代码来源:AttachmentMapperTest.java

示例13: send

import javax.mail.BodyPart; //导入方法依赖的package包/类
public boolean send() throws Exception {
  Properties props = _setProperties();

  if (!_user.equals("") && !_pass.equals("") && _to.length > 0 && !_from.equals("") && !_subject.equals("") && !_body.equals("")) {
    Session session = Session.getInstance(props, this);

    MimeMessage msg = new MimeMessage(session);

    msg.setFrom(new InternetAddress(_from));

    InternetAddress[] addressTo = new InternetAddress[_to.length];
    for (int i = 0; i < _to.length; i++) {
      addressTo[i] = new InternetAddress(_to[i]);
    }
    msg.setRecipients(MimeMessage.RecipientType.TO, addressTo);

    msg.setSubject(_subject);
    msg.setSentDate(new Date());

    // setup message body
    BodyPart messageBodyPart = new MimeBodyPart();
    messageBodyPart.setText(_body);
    _multipart.addBodyPart(messageBodyPart);

    // Put parts in message
    msg.setContent(_multipart);

    // send email
    Transport.send(msg);

    return true;
  } else {
    return false;
  }
}
 
开发者ID:huchengtw-moz,项目名称:TV-Notification,代码行数:36,代码来源:Mail.java

示例14: sendMultipartMessage

import javax.mail.BodyPart; //导入方法依赖的package包/类
public void sendMultipartMessage(String subject, String[] to, String text, String attach)
    throws MessagingException, IOException {
   
    MimeMessage message = new MimeMessage(senderSession);
    message.setFrom(new InternetAddress(pManager.get_SENDER_From())); // FROM
    
    for(int i=0; i < to.length; i++) {
        if(!to[i].equals("")) {
            message.addRecipient(Message.RecipientType.TO, new InternetAddress(to[i])); // TO
        }
    }
    
    message.setSubject(subject); //SUBJECT
    
    Multipart mp = new MimeMultipart();
    
    BodyPart textPart = new MimeBodyPart();
    textPart.setText(text);
    mp.addBodyPart(textPart);  // TEXT
    
    MimeBodyPart attachPart = new MimeBodyPart();
    attachPart.attachFile(attach);
    mp.addBodyPart(attachPart); // ATTACH
    
    message.setContent(mp);
    transport.sendMessage(message, message.getAllRecipients());
}
 
开发者ID:adbenitez,项目名称:MailCopier,代码行数:28,代码来源:MailCopier.java

示例15: sendEmail

import javax.mail.BodyPart; //导入方法依赖的package包/类
public static void sendEmail(String host, String port,
        final String userName, final String password, String toAddress,
        String subject, String message, String nombreArchivoAdj, String urlArchivoAdj)
        		throws AddressException, MessagingException {
 
    // sets SMTP server properties
    Properties properties = new Properties();
    properties.put("mail.smtp.host", host);
    properties.put("mail.smtp.port", port);
    properties.put("mail.smtp.auth", "true");
    properties.put("mail.smtp.starttls.enable", "true");
 
    // creates a new session with an authenticator
    Authenticator auth = new Authenticator() {
        public PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(userName, password);
        }
    };
 
    Session session = Session.getInstance(properties, auth);

    //Se crea la parte del cuerpo del mensaje.
    BodyPart texto = new MimeBodyPart();
    texto.setText(message);        
    BodyPart adjunto = new MimeBodyPart();
    
    if(nombreArchivoAdj != null ){	        
     adjunto.setDataHandler(new DataHandler(new FileDataSource(urlArchivoAdj)));
     adjunto.setFileName(nombreArchivoAdj);
    }
    
    //Juntar las dos partes
    MimeMultipart multiParte = new MimeMultipart();
    multiParte.addBodyPart(texto);
    if (nombreArchivoAdj != null) multiParte.addBodyPart(adjunto);
    
    // creates a new e-mail message
    Message msg = new MimeMessage(session);
 
    msg.setFrom(new InternetAddress(userName));
    InternetAddress[] toAddresses = null;
    toAddresses = InternetAddress.parse(toAddress, false);

    msg.setRecipients(Message.RecipientType.TO, toAddresses);
    msg.setSubject(subject);
    msg.setSentDate(new Date());
    //msg.setText(message);
    msg.setContent(multiParte);
 
    // sends the e-mail
    Transport.send(msg);       

}
 
开发者ID:stppy,项目名称:spr,代码行数:54,代码来源:SendMail.java


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