|
Mail has been edited by Claus Ibsen (Jul 12, 2008). Change summary: CAMEL-485 Mail ComponentThe mail component provides access to Email via Spring's Mail support and the underlying JavaMail system.
URI formatsmtp://[EMAIL PROTECTED]:port[?password=somepwd] pop3://[EMAIL PROTECTED]:port[?password=somepwd] imap://[EMAIL PROTECTED]:port[?password=somepwd]
Mail Message ContentCamel will use the Exchange Message IN body as the MimeMessage Camel copies all the Exchange Message IN headers to the MimeMessage The subject of the MimeMessage from("direct:a").setHeader("subject", subject).to("smtp://[EMAIL PROTECTED]"); Default PortsAs of Camel 1.4 support for default port number has been added. If the port number is omitted Camel will determine based on the protocol the port number to use.
Options
SamplesWe start with a simple route that sends the messages received from a JMS queue as emails. The email account with be the admin account on mymailserver.com. from("jms://queue:subscription").to("smtp://[EMAIL PROTECTED]");
In the next sample we will poll a mailbox for new emails once every minute. Notice that we use the special consumer parameter for setting the poll interval consumer.delay as 60000 millis = 60 seconds. from("imap://[EMAIL PROTECTED]&processOnlyUnseenMessages=true&consumer.delay=60000").to("seda://mails");
In this sample we want to send a mail to multiple recipients. This feature was introduced in camel 1.4. // all the recipients of this mail are: // To: [EMAIL PROTECTED] , [EMAIL PROTECTED] // CC: [EMAIL PROTECTED] // BCC: [EMAIL PROTECTED] String recipients = "&[EMAIL PROTECTED],[EMAIL PROTECTED]&[EMAIL PROTECTED]&[EMAIL PROTECTED]"; from("direct:a").to("smtp://[EMAIL PROTECTED]&[EMAIL PROTECTED]" + recipients); Attachment SampleAttachments is a new feature in Camel 1.4 that of course is also supported by the mail component. In the sample below we send a mail message containing a plain text message with a logo file attachment. // create an exchange with a normal body and attachment to be produced as email Endpoint endpoint = context.getEndpoint("smtp://[EMAIL PROTECTED]"); // create the exchange with the mail message that is multipart with a file and a Hello World text/plain message. Exchange exchange = endpoint.createExchange(); Message in = exchange.getIn(); in.setBody("Hello World"); in.addAttachment("logo.jpeg", new DataHandler(new FileDataSource("src/test/data/logo.jpeg"))); // 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 SampleIn this sample we want to poll our Google mail inbox for mails. Google mail requires to use SSL and have it configured for other clients to access your mailbox. This is done by logging into your google mail and change your settings to allow IMAP access. Google have extensive documentation how to do this. from("imaps://[EMAIL PROTECTED]&password=YOUR_PASSWORD&deleteProcessedMessages=false&processOnlyUnseenMessages=true&consumer.delay=60000").to("log:newmail");
The route above will poll the google mail inbox for new mails once every minute and log it to the newmail logger category. 2008-05-08 06:32:09,640 DEBUG MailConsumer - Connecting to MailStore imaps//imap.gmail.com:993 (SSL enabled), folder=INBOX 2008-05-08 06:32:11,203 DEBUG MailConsumer - Polling mailfolder: imaps//imap.gmail.com:993 (SSL enabled), folder=INBOX 2008-05-08 06:32:11,640 DEBUG MailConsumer - Fetching 1 messages. Total 1 messages. 2008-05-08 06:32:12,171 DEBUG MailConsumer - Processing message: messageNumber=[332], from=[James Bond <[EMAIL PROTECTED]>], [EMAIL PROTECTED], subject=[Camel mail component is now much better], sentDate=[2008-05-08 06:31:44], receivedDate=[2008-05-08 06:34:39] 2008-05-08 06:32:12,187 INFO newmail - Exchange[MailMessage: messageNumber=[332], from=[James Bond <[EMAIL PROTECTED]>], [EMAIL PROTECTED], subject=[Camel mail component is now much better], sentDate=[2008-05-08 06:31:44], receivedDate=[2008-05-08 06:34:39]] SSL Sample with dummyTrustManagerIn the next sample we want to sent mails from Camel using our own mail server using secure connections. As our own mail server is using our own signed certificate we need either to
In the sample we use the dummyTrustManager option: from("seda:mailsToSend").to("imaps://ourmailsserver.com?username=camelmail&password=secret&dummyTrustManager=true"); See Also |
Unsubscribe or edit your notifications preferences
