Fetch mails from another mailbox in Google App Engine - python

I am trying to fetch mails from another mailbox (xxx#domail.com or xxx#gmail.com) in google-app-engine.
I don't want to read mails from appspotmail box as it is being used for different purpose.
Is there any efficient way in which i can make this happen.

Two options:
You could read an inbox via POP/IMAP, but this requires a bit of coding. You also need to have Outgoing Sockets API enabled, which requires you to have a paid app. This approach is async, which means you will constantly need to poll for new messages.
Forward emails to a new appspotmail address (you can have many). This is pretty easy, especially since you already process incoming emails. Since you can have multiple accounts, e.g. xyz#yourappid.appspotmail.com, you can distinguish between them in code.

You can use imap+oauth to read email from a google address. If you google it the very first result is what you need. https://developers.google.com/gmail/oauth_overview

Related

How to send emails according to user request in python?

How do i send an email whenever a user requests it?. I thought on a script that sends mails every hour with some content relevant for the recipients, but I dont like the idea of spamming mail to other people. So i would like to send this mail whenever the recipients wants it. For example if this user sends me a mail with a keyword, i would like the sript to run and send the mail back with the content already made up. So, there is no spam and information is sent in a more efficient way.
I appreciate your help in advance.
This is a pretty complex and broad question.
First off, you would need a server or your PC to have the script running all the time or periodically fire off via cron.
Secondly, you would need to keep some kind of job queue where you would register that a user has sent you an email requesting that you send them one in response. There are well developed and complex job queues like Celery, but you could potentially do with something less complex - maybe a Google Sheets table.
Thirdly, you would need to parse emails you receive in order to get the keywords and email addresses. If you go the gmail + google sheets route, you could do it with some custom code probably, but otherwise you would need to implement email checking on your PC or server. Once you parse them, you add them to the jobs queue.
Finally, you need to provide email access to your Py script - meaning SMTP login. The docs have more on this.
As you can see, there are a lot of things to consider and implement, so you maybe better off trying to narrow down your question a bit. :)

Choosing "From" field using python win32com outlook

I am trying to automate emails using python. Unfortunately, the network administrators at my work have blocked SMTP relay, so I cannot use that approach to send the emails (they are addressed externally).
I am therefore using win32com to automatically send these emails via outlook. This is working fine except for one thing. I want to choose the "FROM" field within my python code, but I simply cannot figure out how to do this.
Any insight would be greatly appreciated.
If you configured a separate POP3/SMTP account, set the MailItem.SendUsingAccount property to an account from the Namespace.Accounts collection.
If you are sending on behalf of an Exchange user, set the MailItem.SentOnBehalfOfName property

checking local email messages with Python

My problem is what's the best strategy for periodically checking a local email account to find if there is any new message(if any, then send these messages to some function to process)?
While during development, we use a Gmail account, so we use a periodic celery task to check the gmail account (through IMAP), and process the emails if there is any.
Now if we implement the mail server by ourselves, shall I still IMAP to the server, or I can just read the files under Maildir? Which is the preferred way?
Actually my problem may not be language-specific, but since I'm using Django/Python, so I just put it in the title. But a general answer about the pros and cons would be enough. Thanks!
Check out the mailbox module:
http://docs.python.org/2/library/mailbox.html
http://docs.python.org/3.3/library/mailbox.html
It would be far faster to just read the messages directly than to interact via IMAP.

Process dynamic email addresses using python

I need to do the following and I was wondering if anyone has done something similar, and if so what they did.
I need to write a program that will handle incoming emails for different clients, process them, and then depending on the email address, do something (add to database, reply, etc).
The thing that makes this a little more challenging is that the email addresses aren't static they are dynamic. For example. The emails would be something like this. dynamic-email1#dynamic-subdomain1.domain.com . The emails are grouped by client using a dynamic subdomain in this example it would be 'dynamic-subdomain1'. A client would have their own subdomain that is assigned to them. Each client can create their own email address under their subdomain, and assign an event to that email. These email addresses and subdomains can change all of the time, new ones added, old ones removed, etc.
So for example if an email comes in for the email 'dynamic-email1#dynamic-subdomain1.domain.com' then I would need to look up in the database to find out which client is assigned the 'dynamic-subdomain1' subdomain and then look to see which event maps to the email address of 'dynamic-email1' and then execute that event. I have the event processing already, I'm just not sure how to map the email addresses to the event.
Since the email addresses are dynamic, it would be a real pain to handle this with file based configuration files, it would be nice to look up in a database instead. I did some research and I found some projects that do something similar but not exactly. The closest that I found is Zed Shaw's Lamson project: http://lamsonproject.org
More background:
I'm using python, django, linux, mysql, memcached currently.
Questions:
Has anyone used Lamson to do what I'm looking to do, how did you like it?
Is there any other projects that do something similar, maybe in a different language besides python?
How would I setup my DNS MX record to handle something like this?
Thanks for your help.
Update:
I did some more research on the google app engine suggestion and it might work but I would need to change too many things and it would add too many moving parts. I would also need a catch all emailer forwarder, anyone know of any good cheap ones? I prefer to deploy on system that handles all email. It looks like people have used postfix listening on port 25 and forwarding requests to lamson. This seems reasonable, I'm going to try it out and see how it goes. I'll update with my results.
Update 2:
I did some more research and I found a couple of websites that do something like this for me, so I'm going to look at them next.
http://mailgun.net
http://www.emailyak.com
I've done some work on a couple projects using dynamic email addresses, but never with dynamic subdomains at the same time. My thoughts on your questions:
I've never used Lamson, so I can't comment on that.
I usually use App Engine's API to receive and handle incoming messages, and it works quite well. You could easily turn each received message into a basic POST request on your own server with e.g. To, From, Subject, and Message fields and handle those with standard django.
One downside with GAE email is having to use *#yourappname.appspotmail.com, but you could get around that by setting up a catch-all email forwarder for *#yourdomain.com to direct everything to secretaddress#yourappname.appspotmail.com. That would let you receive the messages on the custom domain and handle them with GAE.
The other issue/benefit with GAE is using Google's servers instead of your own (at least for the email bit).
For the subdomain issue, you could try setting up wildcard DNS for the MX records, which (in theory) would direct all mail sent to any subdomain to the same server(s). This would enable you to receive email on all subdomains (for better or worse--look out for spam!)
For lamson, have you tried something as simple as:
#route("(address)#(subdomain).(host)", address=".+", subdomain="[^\.]+")
def START(message, address=None, subdomain=None, host=None):
....

Determine if an XMPP user is online or not

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.

Categories