You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Gaffer <se...@fnal.gov> on 2008/04/10 23:54:38 UTC

configuring smtp

I am using Spring ApplicationContext. I have configured SMTP component like
this

	<bean id="smtp"
		class="org.apache.camel.component.mail.MailComponent">
		<property name="configuration">
			<bean
				class="org.apache.camel.component.mail.MailConfiguration">
				<property name="host" value="mail1.department.company.com" />
			</bean>
		</property>
	</bean>

Then I create a route in Java code: 

		from("file://data/input/?noop=true")
			.setHeader("to", "firstname.lastname@company.com")
			.setHeader("from", "firstname.lastname@company.com")
			.setBody(constant("Test"))
			.to("smtp://@");

It fails with error: 

Failed message 1: javax.mail.SendFailedException: Invalid Addresses;
  nested exception is:
	com.sun.mail.smtp.SMTPAddressFailedException: 550 5.1.1
<nu...@mail1.department.company.com>... User unknown
org.springframework.mail.MailSendException; nested exception details (1)
are:
Failed message 1:
javax.mail.SendFailedException: Invalid Addresses;
  nested exception is:
	com.sun.mail.smtp.SMTPAddressFailedException: 550 5.1.1
<nu...@mail1.department.company.com>... User unknown

It tries to use address <nu...@mail1.department.company.com> instead of the
one that I passed in a header in Java code. 

However this code works: 

			Session dummySession = null;
			Properties props = System.getProperties();
			props.put("mail.smtp.host", "mail1.department.company.com");
			Session session = Session.getDefaultInstance(props, null);
			Message msg = new MimeMessage(session);
			InternetAddress ia = new
InternetAddress("firstname.lastname@company.com");
			msg.setFrom(ia);
			msg.setRecipients(Message.RecipientType.TO, 
InternetAddress.parse("firstname.lastname@company.com"));
			msg.setSubject("Test");
			Multipart multipart = new MimeMultipart();
			BodyPart messageBodyPart = new MimeBodyPart();
			String htmlText = "Text";
			messageBodyPart.setContent(htmlText, "text/html");
			multipart.addBodyPart(messageBodyPart);
			msg.setContent(multipart);
			msg.setHeader("X-Mailer", "eInvoiceMailer");
			msg.setSentDate(new Date());
			Transport.send(msg);

How can I make Camel piece work ? 

-- 
View this message in context: http://www.nabble.com/configuring-smtp-tp16619224s22882p16619224.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: configuring smtp

Posted by Gert Vanthienen <ge...@skynet.be>.
L.S.,


Just glanced over the source code, but I think you
- have to add a destination address to your MailComponent configuration
- have to add a user to the MailComponent configuration to become the 
from address

According to the code comments, you can also specify everything in the 
URI with this format smtp:user@host:port/name@address where the part 
behind the / represents the destination address.


Gert

Gaffer wrote:
> I am using Spring ApplicationContext. I have configured SMTP component like
> this
>
> 	<bean id="smtp"
> 		class="org.apache.camel.component.mail.MailComponent">
> 		<property name="configuration">
> 			<bean
> 				class="org.apache.camel.component.mail.MailConfiguration">
> 				<property name="host" value="mail1.department.company.com" />
> 			</bean>
> 		</property>
> 	</bean>
>
> Then I create a route in Java code: 
>
> 		from("file://data/input/?noop=true")
> 			.setHeader("to", "firstname.lastname@company.com")
> 			.setHeader("from", "firstname.lastname@company.com")
> 			.setBody(constant("Test"))
> 			.to("smtp://@");
>
> It fails with error: 
>
> Failed message 1: javax.mail.SendFailedException: Invalid Addresses;
>   nested exception is:
> 	com.sun.mail.smtp.SMTPAddressFailedException: 550 5.1.1
> <nu...@mail1.department.company.com>... User unknown
> org.springframework.mail.MailSendException; nested exception details (1)
> are:
> Failed message 1:
> javax.mail.SendFailedException: Invalid Addresses;
>   nested exception is:
> 	com.sun.mail.smtp.SMTPAddressFailedException: 550 5.1.1
> <nu...@mail1.department.company.com>... User unknown
>
> It tries to use address <nu...@mail1.department.company.com> instead of the
> one that I passed in a header in Java code. 
>
> However this code works: 
>
> 			Session dummySession = null;
> 			Properties props = System.getProperties();
> 			props.put("mail.smtp.host", "mail1.department.company.com");
> 			Session session = Session.getDefaultInstance(props, null);
> 			Message msg = new MimeMessage(session);
> 			InternetAddress ia = new
> InternetAddress("firstname.lastname@company.com");
> 			msg.setFrom(ia);
> 			msg.setRecipients(Message.RecipientType.TO, 
> InternetAddress.parse("firstname.lastname@company.com"));
> 			msg.setSubject("Test");
> 			Multipart multipart = new MimeMultipart();
> 			BodyPart messageBodyPart = new MimeBodyPart();
> 			String htmlText = "Text";
> 			messageBodyPart.setContent(htmlText, "text/html");
> 			multipart.addBodyPart(messageBodyPart);
> 			msg.setContent(multipart);
> 			msg.setHeader("X-Mailer", "eInvoiceMailer");
> 			msg.setSentDate(new Date());
> 			Transport.send(msg);
>
> How can I make Camel piece work ? 
>
>