org.apache.commons.mail.Email.getMimeMessage()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(6.8k)|赞(0)|评价(0)|浏览(116)

本文整理了Java中org.apache.commons.mail.Email.getMimeMessage()方法的一些代码示例,展示了Email.getMimeMessage()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Email.getMimeMessage()方法的具体详情如下:
包路径:org.apache.commons.mail.Email
类名称:Email
方法名:getMimeMessage

Email.getMimeMessage介绍

[英]Returns the internal MimeMessage. Please note that the MimeMessage is built by the buildMimeMessage() method.
[中]返回内部MimeMessage。请注意,MimeMessage是通过buildMimeMessage()方法构建的。

代码示例

代码示例来源:origin: br.com.caelum.vraptor/vraptor-simplemail

RawMessage mail2Content(Email email) throws IOException,
    MessagingException, EmailException {
  email.buildMimeMessage();
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  email.getMimeMessage().writeTo(out);
  return new RawMessage().withData(ByteBuffer.wrap(out.toByteArray()));
}

代码示例来源:origin: com.google.code.maven-play-plugin.org.playframework/play

MimeMessage msg = email.getMimeMessage();
msg.saveChanges();

代码示例来源:origin: stackoverflow.com

Properties props = new Properties();
 props.setProperty("mail.transport.protocol", "smtp");
 Session mailSession = Session.getDefaultInstance(props, null);
 Transport transport = mailSession.getTransport("smtp");
 transport.connect("localhost", 25, null, null);
 Email email = new SimpleEmail();
 email.setFrom("example@example.com");
 email.addTo("example@example.com");
 email.setSubject("Hello Example");
 email.setMsg("Hello Example");
 email.setHostName("localhost"); // buildMimeMessage call below freaks out without this
 // dug into the internals of commons email
 // basically send() is buildMimeMessage() + Transport.send(message)
 // so rather than using Transport, reuse the one that I already have
 email.buildMimeMessage();
 Message m = email.getMimeMessage();
 transport.sendMessage(m, m.getAllRecipients());

代码示例来源:origin: org.apache.commons/commons-email

/**
 * Test sending a image HTML mail bases on a local HTML page and local image.
 *
 * @throws Exception the test failed
 */
@Test
public void testImageHtmlEmailLocal() throws Exception
{
  // use a simple HTML page with one image
  final File htmlFile = new File("./src/test/resources/html/www.apache.org.html");
  final String htmlMsg1 = FileUtils.readFileToString(htmlFile, "ISO-8859-1");
  final ImageHtmlEmail email = (ImageHtmlEmail) create(ImageHtmlEmail.class);
  email.setDataSourceResolver(new DataSourceUrlResolver(htmlFile.getParentFile().toURI().toURL(), false));
  email.setSubject("[testImageHtmlEmail] 1.Test: simple html content");
  email.setHtmlMsg(htmlMsg1);
  EmailUtils.writeMimeMessage( new File("./target/test-emails/testImageHtmlEmailLocal.eml"), send(email).getMimeMessage());
}

代码示例来源:origin: com.atlassian.labs/speakeasy-plugin

try
  email.getMimeMessage().writeTo(bout);
  log.debug("Sent email:\n" + new String(bout.toByteArray()));

代码示例来源:origin: org.apache.commons/commons-email

/**
 * A sanity check that a simple email also works in reality.
 *
 * @throws Exception the test failed
 */
@Test
public void testMultiPartEmail() throws Exception
{
  final MultiPartEmail email = (MultiPartEmail) create(MultiPartEmail.class);
  email.setSubject("TestMultiPartMail");
  email.setMsg("This is a test mail ... :-)");
  email.attach(new File("./src/test/resources/attachments/logo.pdf"));
  EmailUtils.writeMimeMessage( new File("./target/test-emails/multipart.eml"), send(email).getMimeMessage());
}

代码示例来源:origin: org.apache.commons/commons-email

/**
 * A sanity check that a simple email also works in reality.
 *
 * @throws Exception the test failed
 */
@Test
public void testSimpleEmail() throws Exception
{
  final SimpleEmail email = (SimpleEmail) create(SimpleEmail.class);
  email.setSubject("TestSimpleMail");
  email.setMsg("This is a test mail ... :-)");
  EmailUtils.writeMimeMessage( new File("./target/test-emails/simplemail.eml"), send(email).getMimeMessage());
}

代码示例来源:origin: org.apache.commons/commons-email

/**
 * A sanity check that a header folding works correctly.
 *
 * @throws Exception the test failed
 */
@Test
public void testFoldedHeaderValue() throws Exception
{
  final SimpleEmail email = (SimpleEmail) create(SimpleEmail.class);
  email.setSubject("TestFoldedHeaderMail");
  email.setMsg("This is a test mail with a folded header value... :-)");
  email.addHeader("X-TestHeader", "This is a very long header value which should be folded into two lines, hopefully");
  EmailUtils.writeMimeMessage( new File("./target/test-emails/foldedheader.eml"), send(email).getMimeMessage());
}

代码示例来源:origin: org.apache.commons/commons-email

/**
 * This test checks the correct character encoding when sending
 * non-ASCII content using SimpleEmail.
 *
 * https://issues.apache.org/jira/browse/EMAIL-79
 *
 * @throws Exception the test failed
 */
@Test
public void testCorrectCharacterEncoding() throws Exception
{
  // U+03B1 : GREEK SMALL LETTER ALPHA
  // U+03B2 : GREEK SMALL LETTER BETA
  // U+03B3 : GREEK SMALL LETTER GAMMA
  final String subject = "[email] 5.Test: Subject with three greek UTF-8 characters : \u03B1\u03B2\u03B3";
  final String textMsg = "My test body with with three greek UTF-8 characters : \u03B1\u03B2\u03B3\n";
  final String attachmentName = "\u03B1\u03B2\u03B3.txt";
  // make sure to set the charset before adding the message content
  final MultiPartEmail email = (MultiPartEmail) create(MultiPartEmail.class);
  email.setSubject(subject);
  email.setMsg(textMsg);
  // create a proper UTF-8 sequence for the text attachment (matching our default charset)
  final DataSource attachment = new javax.mail.util.ByteArrayDataSource(textMsg.getBytes("utf-8"), "text/plain");
  email.attach(attachment, attachmentName, "Attachment in Greek");
  EmailUtils.writeMimeMessage( new File("./target/test-emails/correct-encoding.eml"), send(email).getMimeMessage());
}

代码示例来源:origin: org.apache.commons/commons-email

/**
 * Testing if we are able to send a partial email with an invalid address.
 *
 * https://issues.apache.org/jira/browse/EMAIL-132
 *
 * @throws Exception the test failed.
 */
@Test
public void testPartialSend() throws Exception
{
  final SimpleEmail email = (SimpleEmail) create(SimpleEmail.class);
  email.addTo(EmailConfiguration.TEST_TO);
  email.addTo("nobody@is.invalid");
  email.setSubject("TestPartialMail");
  email.setMsg("This is a test mail ... :-)");
  email.setSendPartial(true);
  EmailUtils.writeMimeMessage( new File("./target/test-emails/partialmail.eml"), send(email).getMimeMessage());
}

代码示例来源:origin: org.apache.commons/commons-email

htmlEmail1.setHtmlMsg(htmlMsg);
EmailUtils.writeMimeMessage( new File("./target/test-emails/htmlemail1.eml"), send(htmlEmail1).getMimeMessage());
htmlEmail2.attach(url, "Apache Logo", "The official Apache logo" );
EmailUtils.writeMimeMessage( new File("./target/test-emails/htmlemail2.eml"), send(htmlEmail2).getMimeMessage());
htmlEmail3.setHtmlMsg(htmlMsg);
EmailUtils.writeMimeMessage( new File("./target/test-emails/htmlemail3.eml"), send(htmlEmail3).getMimeMessage());
htmlEmail4.attach(attachment);
EmailUtils.writeMimeMessage( new File("./target/test-emails/htmlemail4.eml"), send(htmlEmail4).getMimeMessage());

相关文章

微信公众号

最新文章

更多