powered by Jive Software

Sending message from another user

Hi guys

I have the following situation: I connect to the jabber server as USER_1 and need to send a usual message to USER_2 but from any other existing user, ex. USER_111 (but not from me) …

I know this is possible in jabber to modify FROM field to another login… I did this in Jabber::Net perl library … it realy works !

How can I do this in Smack ?

I can’'t specify FROM in sendMessage(). Do I have to use sendPacket() and setFrom() instead ? Can I send a message by creating an instance of Message class and pass it to sendPacket() ???


Looks like it could be simply done as follows :



Am I right ?

Hi Dmitry,

It seems that Smack does not allow this at its higher level. I ''ve tried this code without success since the receiver received the “Hey” message from userA.

+XMPPConnection con =null ;

try {

con = new XMPPConnection(“server”,5222);

} catch (XMPPException e) {



try {


} catch (XMPPException e1) {



Message pack = new Message(“userB@server”,Message.Type.CHAT);



  • //sends the “Hey” message with the XMPPConnection*


//sends the “Hey” message with a Chat

Chat myChat = con.createChat(“userB@server”);

try {


} catch (XMPPException e2) {


} +

To my mind the XMPPConnection object always correct the “from” field of the packet it has to send…

Hey Dmitry,

AFAIK, what you are trying to do is not allowed by the XMPP spec. The XMPP is very strict in the security area and does not allow to spoof the sender of a message. Otherwise, XMPP servers would be nice targets for spamming.

So even if you manage to change the sender of the message from Smack you will depend on the server that you are using to not rectify that information.


– Gato

I see … thanks

Only components allowed to send messages from other users.

I have a client writen in Smack and a component writtem in Perl.

I’‘m sending an RPC call from client to component with my “specific message protocol” which includes message itself and other parameters … my component accepts it, make all neccessary actions and send a message from the sender’'s name.

I wonder, can I do the same trick with presence… I want my component to set presence for someone. Is it possible in XMPP/ Jabber ?


I wonder, can I do the same trick with presence… I

want my component to set presence for someone. Is it

possible in XMPP/ Jabber ?

Yep, it’'s possible. Components are trusted by the server and they can write the FROM attribute of the packets so you should be able to do that for Presence packets.


– Gato