You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by ivan <iv...@dhousestudio.com> on 2008/10/10 15:30:05 UTC

Servicemix-mail and sender

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.

Re: Servicemix-mail and sender

Posted by timm01 <ti...@mail.ru>.
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 <ti...@mail.ru>:
>>
>> 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%40gmail.com@smtp.gmail.com?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,
>>>> >>> "mymail@mycompany.com");
>>>> >>>
>>>> >>> 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.


Re: Servicemix-mail and sender

Posted by Gert Vanthienen <ge...@gmail.com>.
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 <ti...@mail.ru>:
>
> 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%40gmail.com@smtp.gmail.com?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,
>>> >>> "mymail@mycompany.com");
>>> >>>
>>> >>> 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.
>
>

Re: Servicemix-mail and sender

Posted by timm01 <ti...@mail.ru>.
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%40gmail.com@smtp.gmail.com?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,
>> >>> "mymail@mycompany.com");
>> >>>
>> >>> 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.


Re: Servicemix-mail and sender

Posted by Lars Heinemann <la...@compart.net>.
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%40gmail.com@smtp.gmail.com?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,
> >>> "mymail@mycompany.com");
> >>>
> >>> 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.


Re: Servicemix-mail and sender

Posted by ivan <iv...@dhousestudio.com>.
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%40gmail.com@smtp.gmail.com?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,
>>> "mymail@mycompany.com");
>>>
>>> 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_TAG_
>>>>>>> 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.
> 
> 


Re: Servicemix-mail and sender

Posted by Lars Heinemann <la...@compart.net>.
Ivan,

I would also suggest you post your endpoint config for the mail sender here so 
I can have a look at it.

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,
> > "mymail@mycompany.com");
> >
> > 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_TAG_
> >>>>>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.


Re: Servicemix-mail and sender

Posted by lhe77 <la...@compart.net>.
Ivan,

I can't see a real difference. The only thing is that you do:
    msg.setProperty(MSG_TAG_XXXX, YYYY);	

It seems you defines that constant in your own class? Be sure to use one of
the below:
    msg.setProperty(AbstractMailMarshaler.MSG_TAG_FROM,
"mymail@mycompany.com");
  or 
    msg.setProperty("org.apache.servicemix.mail.from",
"mymail@mycompany.com");


Regards
Lars





ivan-50 wrote:
> 
> 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,
>> "mymail@mycompany.com");
>> 
>> 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_TAG_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-tp19918413p19959445.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: Servicemix-mail and sender

Posted by ivan <iv...@dhousestudio.com>.
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, "mymail@mycompany.com");
> 
> 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_TAG_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.
> 
> 


Re: Servicemix-mail and sender

Posted by Lars Heinemann <la...@compart.net>.
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, "mymail@mycompany.com");

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_TAG_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.


Re: Servicemix-mail and sender

Posted by ivan <iv...@dhousestudio.com>.
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_TAG_FROM
>>> ) .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.
> 
> 


Re: Servicemix-mail and sender

Posted by Lars Heinemann <la...@compart.net>.
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_TAG_FROM
> >) .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.


Re: Servicemix-mail and sender

Posted by ivan <iv...@dhousestudio.com>.
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_TAG_FROM)
>                 .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.
> 
> 


Re: Servicemix-mail and sender

Posted by Lars Heinemann <la...@compart.net>.
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_TAG_FROM)
                .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.