How to send email with Do Not Forward flag using exchangelib - python

This is similar to How to set/access outlook DoNotForward property in Microsoft exchange service but I want to use the exchangelib Python module to send emails.

The building blocks and links to documentation are available in this exhangelib issue: https://github.com/ecederstrand/exchangelib/issues/540
In short, it's really tricky to do if you are not using a Microsoft-supplied library. You have to build a binary message with all sorts of magic variables and send that as a custom extended property. Plus you have to implement the client-side encryption needed by EWS rights management.
AFAIK, no-one has attempted a Python solution yet, and a full solution would require quite a bit of work.

Related

Is it possible to iterate through only open/displayed Outlook emails using Python?

I'm trying to get information into python from an email in Outlook. I'm a beginner with python -- I've done a lot with win32api and selenium, but I haven't written any scripts to work with Outlook at all yet. That being said, I originally figured this would be pretty easy and now it seems like it may not be possible.
Everything I can find about python/Outlook is about looping through the entire inbox or a designated folder (basically handling a batch of emails stored somewhere). I don't want to do that though because the email's sender, subject, body content, folder location, etc. are all variable. I just want to loop through the emails that are currently open. Ideally I will double click on an email to open it from my inbox, run the code, and have the code reference that open email.
It's very easy for me to do this successfully in VBA and I use it all the time. I iterate through all open Outlook windows until a specific phrase (unique to the email I want) is found.
VBA:
For i = 1 To outlookApp.Inspectors.Count
Set eMail = outlookApp.Inspectors.Item(i).CurrentItem
'work with eMail
Python:
[equivalent if possible]
If it's not possible to do this using python, is there some other way that I can specify an individual email from my inbox for the code to reference? At the end of the day, I just need to pull some text out of it. The hard part is telling python which email has the text.
It doesn't matter what programming language is used. Python can be used for automating Outlook as well as other languages.
However, be aware that Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution. Read more about that in the Considerations for server-side Automation of Office article.
A possible workaround is to use a low-level API on which Outlook is based on - Extended MAPI or any other third-party wrapper around that API such as Redemption. EWS is also a possible way to go. Read more about that in the Start using web services in Exchange article.

GCM, how do I know end of XMPP packet?

I'm implementing a Google Cloud Messaging XMPP server in Python. I can connect and authenticate to the GCM, however I use self.ssl_sock.recv(1024) which isn't good, but works for the auth.
However when I later on want to receive messages from the GCM I read on the socket, but how many bytes do I read?? I can't find anything in the xmpp docs about some kind of header which tell length of packet/data.
def read_from_socket(self):
data = self.ssl_sock.recv(??)
self.handle_message(data)
XMPP does not use framing, so there is no header. You need to parse the XML stream using a streaming (e.g SAX) XML parser, such as expat. The XMPP equivalent of a "packet" can be determined by tracking the depth of the parser tree.
However if you're new to XMPP, I strongly recommend using library instead of trying to write all this correctly from scratch yourself.
You're using Python. A good library to start with is SleekXMPP, which is also the library used for code examples in XMPP: The Definitive Guide book.
More info:
Github: https://github.com/fritzy/SleekXMPP
Docs: http://sleekxmpp.readthedocs.org/en/latest/
PyPi: https://pypi.python.org/pypi/sleekxmpp

Does python have a robust pop3, smtp, mime library where I could build a webmail interface?

Does python have a full fledged email library with things for pop, smtp, pop3 with ssl, mime?
I want to create a web mail interface that pulls emails from email servers, and then shows the emails, along with attachments, can display the sender, subject, etc. (handles all the encoding issues etc).
It's one thing to be available in the libraries and another for them to be production ready. I'm hoping someone who has used them to pull emails w/attachments etc. in a production environment can comment on this.
It has all the components you need, in a more modular and flexible arrangement than you appear to envisage -- the standard library's email package deals with the message once you have received it, and separate modules each deal with means of sending and receiving, such as pop, smtp, imap. SSL is an option for each of them (if the counterpart, e.g. mail server, supports it, of course), being basically just "a different kind of socket".
Have you looked at the rich online docs for all of these standard library modules?
http://posterity.edgewall.org/
http://pypi.python.org/pypi/webmail/1.1.7
http://bobomail.sourceforge.net/
Step 1. Download the above.
Step 2. Read the source.
Step 3. See what libraries they use.
Step 4. Use the same libraries.

Writing a Python mail server with authentication

I'm trying to write a simple mail server using Python.
I found smtpd that can be used as a simple smtp server, but I don't think it supports any form of authentication.
For pop or imap, I haven't found anything at all yet.
I do know Twisted has some support for both smtp and pop or imap, but I can't find any examples or tutorials about it.
An alternative would be to use Clojure, but I still have the same question:
Which libraries should I use and is there any documentation about them?
Here is an example from Twisted.
And the main page. Follow the link for documentation to find the example and a tutorial.
Edit:
Check the attachment for this ticket for an example IMAP server. Definitely read the thread as it talks about the shortcomings of the example.
A bit late probably but for experimentation you might also want to check pymta which is a pure-python SMTP implementation I'm using for some experiments/testing. It supports SMTP basic auth. Documentation should be at a 'decent' level, check the examples directory and the unit tests-
For anything production-related I'd go for twisted if you don't mind the asynchronous nature.

Django SMTP and secure password authentication

I have an SMTP server that requires secure password authentication (e.g. Outlook requires to check SPA). Is there a way to deal with it with Django SMTPConnection?
Or maybe ideas about any python solution to deal SPA?
Honestly, I couldn't find enough about SPA, to understand what is it exactly:
en.wikipedia:Secure_Password_Authentication
http://www.kuro5hin.org/?op=displaystory;sid=2002/4/28/1436/66154
The python-ntlm project is a working implementation of NTLM authentication for urllib2. There is a patch floating around in the tracker that allows integration with smtplib.
I would install python-ntlm, then fork smtplib inside your Django project (making sure it gets imported through smtplib) and then patch either smtplib (to always use ntlm authentication) or django (to use python-ntlm).
This will get the work done.
After googling for it I found the same question asked on Google Groups:
http://groups.google.com/group/django-users/browse_thread/thread/fc7f77e2f796e6a4/90ae093cbb2863b8?pli=1
SPA is a proprietary MS protocol for
which there is no documentation. I
don't think you will find a non MS
implementation of SPA.

Categories