本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
}
示例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;
}
}
示例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;
}
}
示例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;
}
}
示例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);
}
示例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));
}
示例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;
}
}
示例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());
}
示例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);
}