本文整理了Java中javax.mail.Message.getFrom()
方法的一些代码示例,展示了Message.getFrom()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.getFrom()
方法的具体详情如下:
包路径:javax.mail.Message
类名称:Message
方法名:getFrom
[英]Returns the "From" attribute. The "From" attribute contains the identity of the person(s) who wished this message to be sent.
In certain implementations, this may be different from the entity that actually sent the message.
This method returns null
if this attribute is not present in this message. Returns an empty array if this attribute is present, but contains no addresses.
[中]返回“From”属性。“发件人”属性包含希望发送此邮件的人的身份。
在某些实现中,这可能与实际发送消息的实体不同。
如果此消息中不存在此属性,则此方法返回null
。如果此属性存在但不包含地址,则返回空数组。
代码示例来源:origin: apache/nifi
/**
* Disposes the message by converting it to a {@link FlowFile} transferring
* it to the REL_SUCCESS relationship.
*/
private void transfer(Message emailMessage, ProcessContext context, ProcessSession processSession) {
long start = System.nanoTime();
FlowFile flowFile = processSession.create();
flowFile = processSession.append(flowFile, out -> {
try {
emailMessage.writeTo(out);
} catch (MessagingException e) {
throw new IOException(e);
}
});
long executionDuration = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start);
String fromAddressesString = "";
try {
Address[] fromAddresses = emailMessage.getFrom();
if (fromAddresses != null) {
fromAddressesString = Arrays.asList(fromAddresses).toString();
}
} catch (MessagingException e) {
this.logger.warn("Failed to retrieve 'From' attribute from Message.");
}
processSession.getProvenanceReporter().receive(flowFile, this.displayUrl, "Received message from " + fromAddressesString, executionDuration);
this.getLogger().info("Successfully received {} from {} in {} millis", new Object[]{flowFile, fromAddressesString, executionDuration});
processSession.transfer(flowFile, REL_SUCCESS);
}
代码示例来源:origin: apache/nifi
Address[] fromAddresses = emailMessage.getFrom();
if (fromAddresses != null) {
fromAddressesString = Arrays.asList(fromAddresses).toString();
代码示例来源:origin: pentaho/pentaho-kettle
break;
case MailInputField.COLUMN_SENDER:
r[index] = StringUtils.join( message.getFrom(), ";" );
break;
case MailInputField.COLUMN_REPLY_TO:
代码示例来源:origin: pentaho/pentaho-kettle
when( message.getSubject() ).thenReturn( SUBJ );
when( message.getFrom() ).thenReturn( adrFr );
when( message.getReplyTo() ).thenReturn( adrRep );
when( message.getAllRecipients() ).thenReturn( adrRecip );
代码示例来源:origin: camunda/camunda-bpm-platform
/**
* Get the addresses to which replies should be directed.
* This will usually be the sender of the message, but
* some messages may direct replies to a different address. <p>
*
* The default implementation simply calls the <code>getFrom</code>
* method. <p>
*
* This method returns <code>null</code> if the corresponding
* header is not present. Returns an empty array if the header
* is present, but contains no addresses.
*
* @return addresses to which replies should be directed
* @exception MessagingException for failures
* @see #getFrom
*/
public Address[] getReplyTo() throws MessagingException {
return getFrom();
}
代码示例来源:origin: com.sun.mail/javax.mail
/**
* Get the addresses to which replies should be directed.
* This will usually be the sender of the message, but
* some messages may direct replies to a different address. <p>
*
* The default implementation simply calls the <code>getFrom</code>
* method. <p>
*
* This method returns <code>null</code> if the corresponding
* header is not present. Returns an empty array if the header
* is present, but contains no addresses.
*
* @return addresses to which replies should be directed
* @exception MessagingException for failures
* @see #getFrom
*/
public Address[] getReplyTo() throws MessagingException {
return getFrom();
}
代码示例来源:origin: oblac/jodd
@Test
void testSimpleTextWithCyrilic() throws MessagingException, IOException {
final Email email = Email.create()
.from("Тијана Милановић <t@gmail.com>")
.to("Јодд <i@jodd.com>")
.subject("Здраво!")
.textMessage("шта радиш?");
final Message message = createMessage(email);
final String content = (String) message.getContent();
assertEquals("шта радиш?", content);
assertTrue(message.getDataHandler().getContentType().contains("text/plain"));
assertEquals("=?UTF-8?B?0KLQuNGY0LDQvdCwINCc0LjQu9Cw0L3QvtCy0LjRmw==?= <t@gmail.com>", message.getFrom()[0].toString());
assertEquals("=?UTF-8?B?0IjQvtC00LQ=?= <i@jodd.com>", message.getRecipients(RecipientType.TO)[0].toString());
}
代码示例来源:origin: camunda/camunda-bpm-platform
/**
* The address comparator.
*
* @param msg The address comparison is applied to this Message
* @return true if the comparison succeeds, otherwise false
*/
public boolean match(Message msg) {
Address[] from;
try {
from = msg.getFrom();
} catch (Exception e) {
return false;
}
if (from == null)
return false;
for (int i=0; i < from.length; i++)
if (super.match(from[i]))
return true;
return false;
}
代码示例来源:origin: apache/nifi
assertEquals("\"test@apache.org\" <NiFi>", message.getFrom()[0].toString());
assertEquals("X-Mailer Header", "TestingNíFiNonASCII", MimeUtility.decodeText(message.getHeader("X-Mailer")[0]));
assertEquals("the message body", message.getContent());
代码示例来源:origin: camunda/camunda-bpm-platform
/**
* Check whether the address string specified in the constructor is
* a substring of the From address of this Message.
*
* @param msg The comparison is applied to this Message's From
* address.
* @return true if the match succeeds, otherwise false.
*/
public boolean match(Message msg) {
Address[] from;
try {
from = msg.getFrom();
} catch (Exception e) {
return false;
}
if (from == null)
return false;
for (int i=0; i < from.length; i++)
if (super.match(from[i]))
return true;
return false;
}
代码示例来源:origin: com.sun.mail/javax.mail
/**
* The address comparator.
*
* @param msg The address comparison is applied to this Message
* @return true if the comparison succeeds, otherwise false
*/
@Override
public boolean match(Message msg) {
Address[] from;
try {
from = msg.getFrom();
} catch (Exception e) {
return false;
}
if (from == null)
return false;
for (int i=0; i < from.length; i++)
if (super.match(from[i]))
return true;
return false;
}
代码示例来源:origin: apache/nifi
assertEquals("test@apache.org", message.getFrom()[0].toString());
assertEquals("from@apache.org", message.getFrom()[1].toString());
assertEquals("X-Mailer Header", "TestingNiFi", message.getHeader("X-Mailer")[0]);
assertEquals("Some Text", message.getContent());
代码示例来源:origin: oblac/jodd
@Test
void testTextHtml() throws MessagingException, IOException {
final Email email = Email.create()
.from(FROM_EXAMPLE_COM)
.to(TO_EXAMPLE_COM)
.subject(SUB)
.textMessage(HELLO)
.htmlMessage("<html><body><h1>Hey!</h1></body></html>");
final Message message = createMessage(email);
assertEquals(1, message.getFrom().length);
assertEquals(FROM_EXAMPLE_COM, message.getFrom()[0].toString());
assertEquals(1, message.getRecipients(RecipientType.TO).length);
assertEquals(TO_EXAMPLE_COM, message.getRecipients(RecipientType.TO)[0].toString());
assertEquals(SUB, message.getSubject());
// wrapper
final MimeMultipart multipart = (MimeMultipart) message.getContent();
assertEquals(1, multipart.getCount());
assertTrue(multipart.getContentType().contains("multipart/mixed"));
// inner content
final MimeBodyPart mimeBodyPart = (MimeBodyPart) multipart.getBodyPart(0);
final MimeMultipart mimeMultipart = (MimeMultipart) mimeBodyPart.getContent();
assertEquals(2, mimeMultipart.getCount());
assertTrue(mimeMultipart.getContentType().contains("multipart/alternative"));
MimeBodyPart bodyPart = (MimeBodyPart) mimeMultipart.getBodyPart(0);
assertEquals(HELLO, bodyPart.getContent());
assertTrue(bodyPart.getDataHandler().getContentType().contains(MimeTypes.MIME_TEXT_PLAIN));
bodyPart = (MimeBodyPart) mimeMultipart.getBodyPart(1);
assertEquals("<html><body><h1>Hey!</h1></body></html>", bodyPart.getContent());
assertTrue(bodyPart.getDataHandler().getContentType().contains(MimeTypes.MIME_TEXT_HTML));
}
代码示例来源:origin: apache/nifi
@Test
public void testOutgoingMessage() throws Exception {
// verifies that are set on the outgoing Message correctly
runner.setProperty(PutEmail.SMTP_HOSTNAME, "smtp-host");
runner.setProperty(PutEmail.HEADER_XMAILER, "TestingNiFi");
runner.setProperty(PutEmail.FROM, "test@apache.org");
runner.setProperty(PutEmail.MESSAGE, "Message Body");
runner.setProperty(PutEmail.TO, "recipient@apache.org");
runner.enqueue("Some Text".getBytes());
runner.run();
runner.assertQueueEmpty();
runner.assertAllFlowFilesTransferred(PutEmail.REL_SUCCESS);
// Verify that the Message was populated correctly
assertEquals("Expected a single message to be sent", 1, processor.getMessages().size());
Message message = processor.getMessages().get(0);
assertEquals("test@apache.org", message.getFrom()[0].toString());
assertEquals("X-Mailer Header", "TestingNiFi", message.getHeader("X-Mailer")[0]);
assertEquals("Message Body", message.getContent());
assertEquals("recipient@apache.org", message.getRecipients(RecipientType.TO)[0].toString());
assertNull(message.getRecipients(RecipientType.BCC));
assertNull(message.getRecipients(RecipientType.CC));
}
代码示例来源:origin: oblac/jodd
final Address[] addresses = msg.getFrom();
代码示例来源:origin: apache/nifi
assertEquals("test@apache.org", message.getFrom()[0].toString());
assertEquals("X-Mailer Header", "TestingNiFi", message.getHeader("X-Mailer")[0]);
assertEquals("recipient@apache.org", message.getRecipients(RecipientType.TO)[0].toString());
代码示例来源:origin: oblac/jodd
private void assertEmail(final Email email) throws MessagingException, IOException {
final Message message = createMessage(email);
assertEquals(1, message.getFrom().length);
assertEquals(FROM_EXAMPLE_COM, message.getFrom()[0].toString());
代码示例来源:origin: oblac/jodd
@Test
void testFromToBccCc() throws MessagingException {
final Email email = Email.create()
.from(FROM_EXAMPLE_COM)
.to(TO1_EXAMPLE_COM).to("Major Tom", "to2@example.com")
.cc(CC1_EXAMPLE_COM).cc("Major Carson", "cc2@example.com")
.bcc("Major Ben", "bcc1@example.com").bcc(BCC2_EXAMPLE_COM);
final Message message = createMessage(email);
assertEquals(1, message.getFrom().length);
assertEquals(FROM_EXAMPLE_COM, message.getFrom()[0].toString());
assertEquals(6, message.getAllRecipients().length);
assertEquals(2, message.getRecipients(RecipientType.TO).length);
assertEquals(TO1_EXAMPLE_COM, message.getRecipients(RecipientType.TO)[0].toString());
assertEquals("Major Tom <to2@example.com>", message.getRecipients(RecipientType.TO)[1].toString());
assertEquals(2, message.getRecipients(RecipientType.CC).length);
assertEquals(CC1_EXAMPLE_COM, message.getRecipients(RecipientType.CC)[0].toString());
assertEquals("Major Carson <cc2@example.com>", message.getRecipients(RecipientType.CC)[1].toString());
assertEquals(2, message.getRecipients(RecipientType.BCC).length);
assertEquals("Major Ben <bcc1@example.com>", message.getRecipients(RecipientType.BCC)[0].toString());
assertEquals(BCC2_EXAMPLE_COM, message.getRecipients(RecipientType.BCC)[1].toString());
}
代码示例来源:origin: spring-projects/spring-integration
/**
* Map the message headers to a Map using {@link MailHeaders} keys; specifically
* maps the address headers and the subject.
* @param source the message.
* @return the map.
*/
public static Map<String, Object> extractStandardHeaders(Message source) {
Map<String, Object> headers = new HashMap<String, Object>();
try {
headers.put(MailHeaders.FROM, convertToString(source.getFrom()));
headers.put(MailHeaders.BCC, convertToStringArray(source.getRecipients(RecipientType.BCC)));
headers.put(MailHeaders.CC, convertToStringArray(source.getRecipients(RecipientType.CC)));
headers.put(MailHeaders.TO, convertToStringArray(source.getRecipients(RecipientType.TO)));
headers.put(MailHeaders.REPLY_TO, convertToString(source.getReplyTo()));
headers.put(MailHeaders.SUBJECT, source.getSubject());
return headers;
}
catch (Exception e) {
throw new MessagingException("conversion of MailMessage headers failed", e);
}
}
代码示例来源:origin: pentaho/pentaho-kettle
.getMessage().getContentType() ) );
logDebug( BaseMessages.getString( PKG, "JobGetMailsFromPOP.EmailFrom.Label", Const.NVL( mailConn
.getMessage().getFrom()[0].toString(), "" ) ) );
logDebug( BaseMessages.getString( PKG, "JobGetMailsFromPOP.EmailSubject.Label", Const.NVL(
mailConn.getMessage().getSubject(), "" ) ) );
内容来源于网络,如有侵权,请联系作者删除!