This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 393d338dfb5 CAMEL-17917 Add missing sample code to camel-mail docs and
update attachments sample to use new Attachments API.
393d338dfb5 is described below
commit 393d338dfb518cbd32cb289a6c46083deefcea28
Author: eidottermihi <[email protected]>
AuthorDate: Thu Apr 7 08:48:11 2022 +0200
CAMEL-17917 Add missing sample code to camel-mail docs and update
attachments sample to use new Attachments API.
---
.../camel-mail/src/main/docs/mail-component.adoc | 39 ++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/components/camel-mail/src/main/docs/mail-component.adoc
b/components/camel-mail/src/main/docs/mail-component.adoc
index a51c75aa7bd..d0f5fcfd9b2 100644
--- a/components/camel-mail/src/main/docs/mail-component.adoc
+++ b/components/camel-mail/src/main/docs/mail-component.adoc
@@ -209,9 +209,27 @@
http://java.sun.com/javaee/5/docs/api/javax/mail/internet/MimeMessage.html[MimeM
can be configured using a header property on the IN message. The code
below demonstrates this:
+[source,java]
+------------------------------------------------------------------------------------------------------------
+from("direct:a").setHeader("subject",
constant(subject)).to("smtp://james2@localhost");
+------------------------------------------------------------------------------------------------------------
+
The same applies for other MimeMessage headers such as recipients, so
you can use a header property as `To`:
+[source,java]
+------------------------------------------------------------------------------------------------------------
+Map<String, Object> headers = new HashMap<String, Object>();
+headers.put("To", "[email protected]");
+headers.put("From", "[email protected]");
+headers.put("Subject", "Camel rocks");
+headers.put("CamelFileName", "fileOne");
+headers.put("org.apache.camel.test", "value");
+
+String body = "Hello Claus.\nYes it does.\n\nRegards James.";
+template.sendBodyAndHeaders("smtp://[email protected]", body, headers);
+------------------------------------------------------------------------------------------------------------
+
When using the MailProducer to send the mail to
server, you should be able to get the message id of the
http://java.sun.com/javaee/5/docs/api/javax/mail/internet/MimeMessage.html[MimeMessage]
@@ -331,6 +349,27 @@ The mail component supports attachments. In the sample
below, we send a
mail message containing a plain text message with a logo file
attachment.
+[source,java]
+-------------------------------------------------------
+// create an exchange with a normal body and attachment to be produced as email
+Endpoint endpoint =
context.getEndpoint("smtp://[email protected]?password=secret");
+
+// create the exchange with the mail message that is multipart with a file and
a Hello World text/plain message.
+Exchange exchange = endpoint.createExchange();
+AttachmentMessage in = exchange.getIn(AttachmentMessage.class);
+in.setBody("Hello World");
+DefaultAttachment att = new DefaultAttachment(new
FileDataSource("src/test/data/logo.jpeg"));
+att.addHeader("Content-Description", "some sample content");
+in.addAttachmentObject("logo.jpeg", att);
+
+// create a producer that can produce the exchange (= send the mail)
+Producer producer = endpoint.createProducer();
+// start the producer
+producer.start();
+// and let it go (processes the exchange by sending the email)
+producer.process(exchange);
+-------------------------------------------------------
+
== SSL sample
In this sample, we want to poll our Google mail inbox for mails. To