https://issues.apache.org/activemq/browse/SMXCOMP-503
Gert Vanthienen wrote: > > L.S., > > Just quickly looked at the code, but you're probably right here. The > MailMarshaler checks if the configuredSender is null or nor, but the > sender can not be null as it is being set to default value in the > validate() method. Could you open a JIRA issue for that? A patch > would be welcome too, btw ;) > > Regards, > > Gert Vanthienen > ------------------------ > Open Source SOA: http://fusesource.com > Blog: http://gertvanthienen.blogspot.com/ > > > > 2009/4/9 timm01 <[email protected]>: >> >> I have the same problem, that Ivan does. >> MailSenderEndpoint has validate method, and it set sender to default, if >> it >> is not set: >> >> public void validate() throws DeploymentException { >> ... >> if (this.sender == null) { >> this.sender = this.marshaler != null >> ? this.marshaler.getDefaultSenderForOutgoingMails() : >> AbstractMailMarshaler.DEFAULT_SENDER; >> } >> } >> >> >> >> >> >> lhe77 wrote: >>> >>> Looks fine so far. >>> >>> >>> Am Mittwoch 15 Oktober 2008 10:53:43 schrieb ivan: >>>> Lars Heinemann пишет: >>>> > Ivan, >>>> > >>>> > I would also suggest you post your endpoint config for the mail >>>> sender >>>> > here so I can have a look at it. >>>> >>>> Hi Lars! >>>> >>>> Here is my xbean.xml of mail sender. >>>> >>>> >>>> <mail:sender service="my:mailSenderService" >>>> endpoint="senderEndpoint" >>>> debugMode="true" >>>> connection="#connection" >>>> /> >>>> >>>> <bean id="connection" class="java.lang.String"> >>>> <constructor-arg> >>>> <value>smtps://j.test.my.test.log%[email protected]?password=xxxxx >>>></value> </constructor-arg> >>>> </bean> >>>> >>>> >>>> Truly yours, >>>> Ivan Pryvalov. >>>> >>>> > Regards >>>> > Lars >>>> > >>>> > Am Montag 13 Oktober 2008 17:23:01 schrieb ivan: >>>> >> Hi Lars! >>>> >> >>>> >> My code looks like : >>>> >> >>>> >> <<< SomeClass implements MessageExchangeListener; >>>> >> >>>> >> ServiceMixClient client = new ServiceMixClientFacade(context); >>>> >> EndpointResolver tmpER = client.createResolverForService(destQname); >>>> >> InOnly io = client.createInOnlyExchange(tmpER); >>>> >> NormalizedMessage msg = io.getInMessage(); >>>> >> msg.setProperty(MSG_TAG_XXXX, YYYY); >>>> >> ... >>>> >> client.send(io); >>>> >> >>>> >> >>>> >> >>>> >> >>>> >> What is principal difference between my code and yours? >>>> >> >>>> >> Thanks, >>>> >> Truly yours, >>>> >> Ivan Pryvalov. >>>> >> >>>> >> Lars Heinemann пишет: >>>> >>> Ivan, >>>> >>> >>>> >>> it should work if you put the property to the normalized message... >>>> >>> >>>> >>> For example: >>>> >>> >>>> >>> MessageExchange me = ....; >>>> >>> NormalizedMessage nmsg = me.createMessage(); >>>> >>> >>>> >>> nmsg.setProperty(AbstractMailMarshaler.MSG_TAG_FROM, >>>> >>> "[email protected]"); >>>> >>> >>>> >>> me.setMessage(nmsg, "in"); >>>> >>> getChannel().send(me); >>>> >>> >>>> >>> The property has to be set on the In-Message...not on the message >>>> >>> exchange. >>>> >>> >>>> >>> Regards >>>> >>> Lars >>>> >>> >>>> >>> Am Montag 13 Oktober 2008 16:48:33 schrieb ivan: >>>> >>>> Hi Lars! >>>> >>>> >>>> >>>> Ok, I just tried to set sender via NM, but I can not do it. >>>> >>>> >>>> >>>> <<< >>>> >>>> if there is a preconfigured sender for the endpoint from >>>> xbean.xml, >>>> it >>>> >>>> will be used >>>> >>>> else if MSG_TAG_FROM is defined in the message properties, then it >>>> >>>> will be used >>>> >>>> else the method getDefaultSender() of the marshaler is invoked >>>> >>>> >>>> >>>> >>>> >>>> I wanted to set tag "From" via second way. But it my tests it >>>> didn't >>>> >>>> work. I back to first way :) >>>> >>>> >>>> >>>> >>>> >>>> Truly yours, >>>> >>>> Ivan Pryvalov. >>>> >>>> >>>> >>>> Lars Heinemann пишет: >>>> >>>>> Ivan, >>>> >>>>> >>>> >>>>> I don't understand your question? >>>> >>>>> >>>> >>>>> Looking at the code... >>>> >>>>> >>>> >>>>> if (this.sender == null) { >>>> >>>>> this.sender = this.marshaler != null >>>> >>>>> ? >>>> this.marshaler.getDefaultSenderForOutgoingMails() >>>> : >>>> >>>>> AbstractMailMarshaler.DEFAULT_SENDER; >>>> >>>>> } >>>> >>>>> >>>> >>>>> Given the situation, a marshaler returns NULL on method >>>> >>>>> getDefaultSenderForOutgoingMails() you would run into a NPE >>>> without >>>> >>>>> this check. So this check is absolute needed here. >>>> >>>>> >>>> >>>>> Regards >>>> >>>>> Lars >>>> >>>>> >>>> >>>>> Am Montag 13 Oktober 2008 12:56:41 schrieb ivan: >>>> >>>>>> Hi Lars! >>>> >>>>>> >>>> >>>>>> All shown code has check on Null: >>>> >>>>>> >>>> >>>>>> <<< >>>> >>>>>> if (from != null) { >>>> >>>>>> mimeMessage.setFrom(from); >>>> >>>>>> } >>>> >>>>>> >>>> >>>>>> >>>> >>>>>> >>>> >>>>>> As far as I understood, anyway "from" is set either from >>>> >>>>>> "this.sender" or >>>> >>>>>> "this.marshaler.getDefaultSenderForOutgoingMails()". >>>> >>>>>> So, we can not get situation (from==null). It is correct? >>>> >>>>>> >>>> >>>>>> Ivan Pryvalov. >>>> >>>>>> >>>> >>>>>> Lars Heinemann пишет: >>>> >>>>>>> Ivan, >>>> >>>>>>> >>>> >>>>>>> you only look at one aspect of the logic. >>>> >>>>>>> Please have a look at the DefaultMailMarshaler class. >>>> >>>>>>> >>>> >>>>>>> protected void fillMailHeaders(MimeMessage mimeMessage, >>>> >>>>>>> MessageExchange exchange, >>>> >>>>>>> NormalizedMessage nmsg, >>>> String >>>> >>>>>>> configuredSender, String configuredReceiver) >>>> >>>>>>> throws Exception { >>>> >>>>>>> >>>> >>>>>>> ... >>>> >>>>>>> >>>> >>>>>>> // fill the "From" field of the mail >>>> >>>>>>> if (configuredSender != null && >>>> >>>>>>> configuredSender.trim().length() >>>> >>>>>>> >>>> >>>>>>>> 0) { // if sender is configured through xbean then use it >>>> Address >>>> >>>>>>>> from >>>> >>>>>>> >>>> >>>>>>> = InternetAddress.parse(configuredSender)[0]; if (from != null) >>>> { >>>> >>>>>>> mimeMessage.setFrom(from); >>>> >>>>>>> } >>>> >>>>>>> } else if >>>> >>>>>>> (nmsg.getProperty(AbstractMailMarshaler.MSG_TAG_FROM) != null) >>>> { >>>> >>>>>>> // use the delivered From field from the message >>>> >>>>>>> Address from = >>>> >>>>>>> >>>> InternetAddress.parse(nmsg.getProperty(AbstractMailMarshaler.MSG_TA >>>> >>>>>>>G_ FR OM ) .toString())[0]; >>>> >>>>>>> if (from != null) { >>>> >>>>>>> mimeMessage.setFrom(from); >>>> >>>>>>> } >>>> >>>>>>> } else { >>>> >>>>>>> // there was no From field delivered, so use the >>>> >>>>>>> default sender Address from = >>>> >>>>>>> InternetAddress.parse(getDefaultSenderForOutgoingMails())[0]; >>>> >>>>>>> if (from != null) { >>>> >>>>>>> mimeMessage.setFrom(from); >>>> >>>>>>> } >>>> >>>>>>> } >>>> >>>>>>> >>>> >>>>>>> ... >>>> >>>>>>> >>>> >>>>>>> >>>> >>>>>>> I hope this makes it more clear to you. If you write your own >>>> >>>>>>> marshaler, then you are also responsible for filling the mail >>>> >>>>>>> properties correctly. When using the default marshaler, all >>>> should >>>> >>>>>>> work fine if you did it correct. >>>> >>>>>>> >>>> >>>>>>> Regards >>>> >>>>>>> Lars >>>> >>>>>>> >>>> >>>>>>> Am Freitag 10 Oktober 2008 15:30:05 schrieb ivan: >>>> >>>>>>>> Hi! >>>> >>>>>>>> >>>> >>>>>>>> I read at http://servicemix.apache.org/servicemix-mail.html: >>>> >>>>>>>> >>>> >>>>>>>> <<< >>>> >>>>>>>> How is the sender determined? >>>> >>>>>>>> >>>> >>>>>>>> if there is a preconfigured sender for the endpoint from >>>> >>>>>>>> xbean.xml, it will be used >>>> >>>>>>>> else if MSG_TAG_FROM is defined in the message properties, >>>> then >>>> it >>>> >>>>>>>> will be used >>>> >>>>>>>> else the method getDefaultSender() of the marshaler is invoked >>>> >>>>>>>> >>>> >>>>>>>> >>>> >>>>>>>> >>>> >>>>>>>> Also I looked at the source (I downloaded it some month ago >>>> from >>>> >>>>>>>> 3.3-SNAPSHOT): >>>> >>>>>>>> >>>> >>>>>>>> <<< MailSenderEndpoint.java >>>> >>>>>>>> >>>> >>>>>>>> public void validate() throws DeploymentException { >>>> >>>>>>>> super.validate(); >>>> >>>>>>>> >>>> >>>>>>>> if (this.config == null || this.connection == null) { >>>> >>>>>>>> throw new DeploymentException("No valid >>>> connection >>>> >>>>>>>> uri provided."); >>>> >>>>>>>> } >>>> >>>>>>>> if (this.sender == null) { >>>> >>>>>>>> this.sender = this.marshaler != null >>>> >>>>>>>> ? >>>> >>>>>>>> this.marshaler.getDefaultSenderForOutgoingMails() >>>> >>>>>>>> >>>> >>>>>>>> : AbstractMailMarshaler.DEFAULT_SENDER; >>>> >>>>>>>> >>>> >>>>>>>> } >>>> >>>>>>>> } >>>> >>>>>>>> >>>> >>>>>>>> >>>> >>>>>>>> >>>> >>>>>>>> So, it seems, there is no way to configure "sender" header for >>>> >>>>>>>> e-mail via MSG_TAG_FROM. >>>> >>>>>>>> >>>> >>>>>>>> Am I right? Or maybe it is already fixed? >>>> >>>>>>>> >>>> >>>>>>>> Truly yours, >>>> >>>>>>>> Ivan Pryvalov. >>> >>> >>> >> >> -- >> View this message in context: >> http://www.nabble.com/Servicemix-mail-and-sender-tp19918413p22969255.html >> Sent from the ServiceMix - User mailing list archive at Nabble.com. >> >> > > > ----- > --- > Gert Vanthienen > http://gertvanthienen.blogspot.com > -- View this message in context: http://www.nabble.com/Servicemix-mail-and-sender-tp19918413p22984037.html Sent from the ServiceMix - User mailing list archive at Nabble.com.
