title: How to send multicast message (multiple users) using xmpp and Python xmpppy (XEP-0033: Extended Stanza Addressing)
body: <p>I am using xmpppy <a href="http://xmpppy.sourceforge.net/" rel="nofollow">http://xmpppy.sourceforge.net/</a> to send Jabber notifications, it is working well for single destinations using the following code:</p>
  
  <pre><code># pip install https://github.com/rochacbruno/xmpppy/tarball/master
  
  import xmpp
  
  JABBER_SETTINGS = {"USERNAME": None, "PASSWORD": None, "DOMAIN": None, "RESOURCE": None}    
  
  def get_jabber_client():
      client = xmpp.Client(JABBER_SETTINGS.get('DOMAIN'))
      client.connect(server=(JABBER_SETTINGS.get('DOMAIN'), '5222'))
      client.auth(
          JABBER_SETTINGS.get('USERNAME'),
          JABBER_SETTINGS.get('PASSWORD'), 
          JABBER_SETTINGS.get('RESOURCE')
      )
      client.sendInitPresence()
      return client
  
  def send_message(to, message):
      client = get_jabber_client()
      xmpp_message = xmpp.Message(to, message)
      client.send(xmpp_message)
      client.disconnect()
  
  send_message("single.destination@domain.com", "Hello World!")
  </code></pre>
  
  <p>But now I need to send the message to multiple destinations, for now I am doing.</p>
  
  <pre><code>for users in list_of_users:
      send_message(user, "Hello World!")
  </code></pre>
  
  <p>Which works fine, but every time I call it starts the process of authentication and takes a lot of time.</p>
  
  <p>I've tried to create a single client and use the same client to send the message.</p>
  
  <pre><code>def send_message(to, message):
      if isinstance(to, basestring):
          to = [to]
      assert isinstance(to, (list, tuple))
      client = get_jabber_client()
      for destination in to:
          xmpp_message = xmpp.Message(destination, message)
          client.send(xmpp_message)
      client.disconnect()
  
  send_message(['user1...', 'user2...'], "Hello World!")
  </code></pre>
  
  <p>The code above works, but only the first user in the list gets the message well formatted, the other users receives the message in pure XML.</p>
  
  <p>I saw this code (in .net), mentioning XEP-0033: Extended Stanza Addressing <a href="http://forum.ag-software.net/thread/1482-Send-Message-To-all-users-in-contact-list" rel="nofollow">http://forum.ag-software.net/thread/1482-Send-Message-To-all-users-in-contact-list</a></p>
  
  <pre><code>var addresses = new Addresses();
  addresses.AddAddress(new Address
                {
                    Type = Type.to,
                    Jid = "hildjj@jabber.org/Work",
                    Description = "Joe Hildebrand"
                });
  
  addresses.AddAddress(new Address
          {
              Type = Type.cc,
              Jid = "jer@jabber.org/Home",
              Description = "Jeremie Miller"
          });
  
  var msg = new Matrix.Xmpp.Client.Message();
  
  msg.Add(addresses);
  msg.To = "multicast.jabber.org";
  msg.Body = "Hello, world!";
  
  builds the following Xml:
  
  &lt;message to='multicast.jabber.org'&gt;
     &lt;addresses xmlns='http://jabber.org/protocol/address'&gt;
         &lt;address type='to' jid='hildjj@jabber.org/Work' desc='Joe Hildebrand'/&gt;
         &lt;address type='cc' jid='jer@jabber.org/Home' desc='Jeremie Miller'/&gt;
     &lt;/addresses&gt;
     &lt;body&gt;Hello, world!&lt;/body&gt;
  &lt;/message&gt;
  </code></pre>
  
  <p>But I did not found the way to do the same in Python using xmpppy, any idea on how to build the multicast stanza and send the message to multiple users using Python? </p>
  
  <p>Thanks.</p>