<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#ffffff">
    Sorry for delay, I was a bit busy.<br>
    <br>
    Here is how I send messages using exmpp:<br>
    _________________________________________________<br>
    <br>
    %% Defining the internet address of the server:<br>
    Server = "myserver",<br>
    <br>
    %% Create session<br>
    MySession = exmpp_session:start(),<br>
    <br>
    %% Create sender JID (= MyJID);<br>
    %% XMPP client ID (user resources) = exmpp (use random if not
    filtered packets);<br>
    %% USER = user nick<br>
    MyJID = exmpp_jid:make(User, Server, "exmpp"),<br>
    <br>
    %% Create a new session with basic (digest) authentication,<br>
    %% with Password = your account password<br>
    exmpp_session:auth_basic_digest(MySession, MyJID, Password),<br>
    <br>
    %% Connect in standard TCP:<br>
    {ok, _StreamId} = exmpp_session:connect_TCP(MySession, Server,
    5222),<br>
    <br>
    %% Login with defined JID / Authentication:<br>
    try exmpp_session:login(MySession)<br>
    catch<br>
    throw:{auth_error, 'not-authorized'} -><br>
       %% Throw a message to the prompter line:<br>
       io:format("Error: not authorized attempt in ~p.~n",[MySession])<br>
    end,<br>
    <br>
    %% If login OK, explicitly send presence:<br>
     exmpp_session:send_packet(MySession,exmpp_presence:set_status(exmpp_presence:available(),
    "transmitting")),<br>
    <br>
    %% Creating the packet needed to be sent<br>
    %% with To = nick@server<br>
    %% and Body = "a string message"<br>
    Packet =
    exmpp_stanza:set_sender(exmpp_stanza:set_recipient(exmpp_message:chat(Body),
    To), From),<br>
    <br>
    %% Sending the packet:<br>
    exmpp_session:send_packet(MySession, Packet),<br>
    __________________________________________________<br>
    <br>
    I hope it will help you.<br>
    <br>
    CGS<br>
    <br>
    <br>
    On 11/03/2011 08:30 AM, Alexander Kuleshov wrote:
    <blockquote
cite="mid:CANCZXo7V0rJ5o6J+ugp_OScYt_3QsxFfz0e_mRi6usqW2xUPmQ@mail.gmail.com"
      type="cite">
      <div>Hello,<br>
      </div>
      <div><br>
      </div>
      <div>I have simple ejabebrd plugin and i need to esn message from
        it.</div>
      <div><br>
      </div>
      <div>My code:</div>
      <div><br>
      </div>
      <div>send_message(TypeStr, BodyStr) -><br>
            LUser = "test1",<br>
            LServer = "localhost",<br>
            From1 = jlib:make_jid(LUser, LServer, "fb"),<br>
        <br>
            TUser = "test2",<br>
            TServer = "localhost",<br>
            To1 = jlib:make_jid(TUser, TServer, "fb"),<br>
        <br>
            FromAddress = jlib:jid_to_string(From1),<br>
            ToAddress = jlib:jid_to_string(To1),<br>
        <br>
            XmlBody = {xmlelement, "message", [{"type", TypeStr},
        {"from", FromAddress}, {"to", ToAddress}], [{xmlelement, "body",
        [], [{xmlcdata, BodyStr}]}]},<br>
           ejabberd_router:route(From, To, XmlBody).</div>
      <div><br>
      </div>
      <div>But i get error:</div>
      <div><br>
      </div>
      <div>=ERROR REPORT==== 2011-11-03 13:27:12 ===<br>
        E(<0.494.0>:ejabberd_router:70) : {{badrecord,jid},<br>
                                                         
        [{ejabberd_router,do_route,3},<br>
                                                         
        {ejabberd_router,route,3},<br>
                                                         
        {mod_poker,on_register,3},<br>
                                                         
        {ejabberd_hooks,run1,3},<br>
                                                         
        {ejabberd_c2s,wait_for_auth,2},<br>
                                                       
         {p1_fsm,handle_msg,10},<br>
                                                       
         {proc_lib,init_p_do_apply,3}]}<br>
        when processing: {"test1@localhost","test2@localhost",<br>
        {xmlelement,"message",<br>
        [{"type","chat"},<br>
          {"from","test1@localhost/fb"},<br>
          {"to","test2@localhost/fb"}],<br>
          [{xmlelement,"body",[],[{xmlcdata,"test test"}]}]}}<br>
      </div>
      <div><br>
      </div>
      <div>How can i fix it? How can i send message from ejabberd
        plugin?</div>
      <div><br>
      </div>
      <div>Thank you.</div>
      <pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
ejabberd mailing list
<a class="moz-txt-link-abbreviated" href="mailto:ejabberd@jabber.ru">ejabberd@jabber.ru</a>
<a class="moz-txt-link-freetext" href="http://lists.jabber.ru/mailman/listinfo/ejabberd">http://lists.jabber.ru/mailman/listinfo/ejabberd</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>