I'm using XMPP in Python, and I can send messages, but how can I receive?
I must register a handler and process:
def messageCB(sess,mess):
print 'MESSAGE'*100
nick=mess.getFrom().getResource()
text=mess.getBody()
#print mess,nick
print text
client.RegisterHandler('message',messageCB)
while 1:
client.Process(1)
Good post. I notice this code snippet is also in the logger example in xmpppy sourceforge website.
I wonder if it is possible to reply to incoming messages. The code above only receives and the nickname resource ID does not indicate who the sender is (in terms of JID format, user#server) unless xmpppy can translate that appropriately. So how might one take the received message nd "echo" it back to the sender? Or is that not easily possible with the xmpppy library and need to find a different XMPP library?
Related
I already have the main script. Now I only need the method that will send a certaing message from my account (my name) to another person automatically. Is it possible to send messages that way?
You would have to use the Telegram Database Library, which is a set of APIs you can use to control your user's actions via HTTP requests. Then you'll use the sendMessage class to send a message as yourself. The Get Started page pretty much has everything you need for your project.
Source: https://core.telegram.org/#tdlib-build-your-own-telegram
I am using Python API for sending messages in LinkedIn.
I found that
api.SendMessage("This is a test subject", "This is the test body", [pid])
can send messages only to the ones who are in our connected list and not others.
How do you send messages to anyone who is not in our connect list?
As I answered elsewhere, this is how LinkedIn behaves, whether you use the API or not. You can only message first degree connections.
There is an InMail feature that allows for messaging outside your first degree network, but that is a paid product. Is that something you're interested in?
Or the other option is to have a person between the sending and recipient agree to "pass the message along." That is not available via the API, however.
That's all I say here, as we're now outside the scope of technical questions.
I'm using the xmpppy library to write an XMPP client that can chat with users. It has its own XMPP user account and needs to know if a given user is online. However, the documentation is a bit sparse on how to do this. What would you recommend?
The only solution I've seen thus far is to start up a daemon before the XMPP server starts and monitor all presence messages that are sent out - then a user is said to be online if they've sent the "I'm online"-type message but not the corresponding "I'm logging off" message. However, being new to XMPP in general, I would think there would be a nicer way to do this.
The simple way is to support "subscribe" presence message -- this lets another user check if you're currently present (if they don't already know) by a "subscribe" attempt. Check this useful guide to get started, and the standard for many more important details (esp. on protecting your privacy, if needed, from subscribe requests from user you don't know).
There are basically three ways to connect to an XMPP server: as a client (which you've done), as a component, and as another server. The server-to-server type (s2s) is just a federated connection, very much like how mail servers exchange email with each other.
Alex described how clients keep track of presence. XMPP requires me to approve that you can receive my presence information and vice versa. For your bot this means for you to keep track of who's online the end users need to accept your presence requests. It also means that you can respond to the user's presence requests and keep them informed about if your bot is up or not.
The last way is as a trusted component, and only works if you're running the server. i.e. if you're trying to do this on the jabber.org server, you're out of luck, because you're not running that server. The upsdie is you can have access to the internals of the XMPP server, like pulling lists of everyone who's online. The downside is your component / bot implementation is going to be different for every server implementation.
I'm coding by python about Gtalk I use XMPPPY.
But I can chat with GTalk client but the problem is I can't accept invitation.
Is XMPPY can do ?
Looks like you want to "authorize" the request. I'm assuming you've received the request at the client. In the roster class (xmpp.roster) there is an "Authorize" method. It sends the "subscribed" packet to accept the roster request. This is what the method looks like:
def Authorize(self,jid):
""" Authorise JID 'jid'. Works only if these JID requested auth previously. """
self._owner.send(Presence(jid,'subscribed'))
Wait, that may not be what you're asking at all. Are you trying to process a chat or a roster request? Take a look at the example (small) client they have called xtalk.py. I think you're interested in the xmpp_message method.
I have a postfix server listening and receiving all emails received at mywebsite.com Now I want to show these postfix emails in a customized interface and that too for each user
To be clear, all the users of mywebsite.com will be given mail addresses like someguy#mywebsite.com who receives email on my production machine but he sees them in his own console built into his dashboard at mywebsite.com.
So to make the user see the mail he received, I need to create an email replica of the postfix mail so that mywebsite(which runs on django-python) will be reflecting them readily. How do I achieve this. To be precise this is my question, how do I convert a postfix mail to a python mail object(so that my system/website)understands it?
Just to be clear I have written psuedo code to achieve what I want:
email_as_python_object = postfix_email_convertor(postfix_email)
attachments_list = email_as_python_object.attachments
body = email_as_python_object.body # be it html or whatever
And by the way I have tried default email module which comes with python but thats not handy for all the cases. And even I need to deal with mail attachments manually(which I hate). I just need a simple way to deal with cases like these(I was wondering how postfix understands a email received. ie.. how it automatically figures out different headers,attachments etc..). Please help me.
You want to have postfix deliver to a local mailbox, and then use a webmail system for people to access that stored mail.
Don't get hung up on postfix - it just a transfer agent - it takes messages from one place, and puts them somewhere else, it doesn't store messages.
So postfix will take the messages over SMTP, and put them in local mail files.
Then IMAP or some webmail system will display those messages to your users.
If you want the mail integrated in your webapp, then you should probably run an IMAP server, and use python IMAP libraries to get the messages.
First of all, Postfix mail routing rules can be very complex and your presumably preferred solution involves a lot of trickery in the wrong places. You do not want to accidentally show some user anothers mails, do you? Second, although Postfix can do almost anything, it shouldn't as it only is a MDA (mail delivery agent).
Your solution is best solved by using a POP3 or IMAP server (Cyrus IMAPd, Courier, etc). IMAP servers can have "superuser accounts" who can read mails of all users. Your web application can then connect to the users mailbox and retreive the headers and bodys.
If you only want to show the subject-line you can fetch those with a special IMAP command and very low overhead. The Python IMAP library has not the easiest to understand API though. I'll give it a shot (not checked!) with an example taken from the standard library:
import imaplib
sess = imaplib.IMAP4()
sess.login('superuser', 'password')
# Honor the mailbox syntax of your server!
sess.select('INBOX/Luke') # Or something similar.
typ, data = sess.search(None, 'ALL') # All Messages.
subjectlines = []
for num in data[0].split():
typ, msgdata = sess.fetch(num, '(RFC822.SIZE BODY[HEADER.FIELDS (SUBJECT)])')
subject = msgdata[0][1].lstrip('Subject: ').strip()
subjectlines.append(subject)
This logs into the IMAP server, selects the users mailbox, fetches all the message-ids then fetches (hopefully) only the subjectlines and appends the resulting data onto the subjectlines list.
To fetch other parts of the mail vary the line with sess.fetch. For the specific syntax of fetch have a look at RFC 2060 (Section 6.4.5).
Good luck!
I'm not sure that I understand the question.
If you want your remote web application to be able to view users' mailbox, you could install a pop or imap server and use a mail client (you should be able to find one off the shelf) to read the emails. Alternatively, you could write something to interrogate the pop/imap server using the relevant libraries that come with Python itself.
If you want to replicate the mail to another machine, you could use procmail and set up actions to do this. Postfix can be set up to invoke procmail in this wayy.