Package: mbox2m365
AbstractThis repository contains a simple python script that (1) processes anmboxstyle mailbox file, (2) parses out (typically) the last message
and then (3) re-transmits this using the CLIm365toolset. While this
script can be used in a completely stand-alone manner to extract a
message from anmboxand thensendusingm365, it’s main utility
is when used in a full ecosystem including an email client andpostfixserver.The CLIm365offers the ability to use Outlook/Office365 to send
emails. However, this tool is not suited to use as a mail client — it
merely offers a means to transmit a message from the command line. More
useful would be if existing mail clients could leveragem365natively.
Currently, however, this is not available. Therefore,mbox2m365was
created to complete a "missing link" in a full email experience. Using
this tool in a configured environment, it is now possible to useanyemail client to transmit messages using Outlook/Office365.TL;DREven if you’re impatient, it’s a good idea to read this document.
However, assuming you’ve already built the infrastructure, assuming you
have installedm365(and logged into your Institution fromm365),
have assuming you have setup your email client to email to a dummy local
postfix account, then you can installmbox2m365with a simplepipinstallmbox2m365note at time of writing the PyPI install might not be available. In that
case, simply clone this repo and do a# From the repo root dirpipinstall-U.and fire it off by setting up the monitor on themboxfile (here we
assume the mbox belongs torudolph)cd/var/mail
find.|entrmbox2m365--mboxrudolph--b64_encode\--sendFromFile--cleanUp\--waitForStragglers5(Clearly the above relies onentr.
Consult your distro’s repos for the appropriate install. In arch, this
isyay -S entr, in Ubuntu, this issudo apt install entr)Security alert!Wait!Danger, Will Robinson! Doesn’t this violate security policies?
I was told my Institution doesnotallow clients like thunderbird to
connect to the Outlook server to send emails!Well, the devil is in the details as the saying goes. This solution doesnotviolate policy since the "unauthenticated" email client isnotever connecting/authenticating to the Outlook server. Rather, the
"unauthenticated" email client sends messages to a specially configured
server that "saves" the emails to a file. Then, a separate program
teases out the new arrivals and uses theauthenticatedm365program to actually talk to and leverage Outlook to send the email. Thisseparate programthat bridges the mail file tom365is none other
than this python module.So to be pendantic: all credentialing and authentication is handled bym365andnotthis tool. The end user is still required to
login/authenticate usingm365. If this has not happened, thenmbox2m365will not work.Again, this repo containsnoauthentication tokens/passwords/etc.LimitationsLet’s get these out of the way first. This isnota full solution for
linking a third party email client to Outlook. It getsclose, IMHO.
The limitations are:This is not a multi-user solution. All email transmitted to the
intermediate helper server is added to a single usermboxwhich when
processed by this script meansallemail in thatmboxwill
appear to have been transmitted by that user. While in theory it
should be possible to support multiple users, either by having a
separate helper server per user or by having multiple local users on
the mail server and separatemboxfiles, the current solution is
clearly not scalable. It is decent though for the single user case.Fundmanentally, this solution is limited first and foremost by the
capabilities of the CLIm365 outlook mail sendfunctionality. Recent
updates tom365have expanded functionality of this bridge — most
notably attachments are now supported. Still pending is fullbccsupport — currently allbccrecipients are switched tocc.Other limitations stem from the fact the bridge needs to process themboxfilede novoeach time mail is received by the helper server.
This means that time to process will increase linearly withmboxsize.
The real world implications of this are still being explored.Finally, the bridge does make a best effort attempt towaituntil themboxhas stabilized before analyzing it. When sending emails to
multiple recipients,eachrecipient gets a single complete copy in themboxwith a single address (the multiple recipient addresses are not
conserved in themboxbutareprocessed by this bridge). While
arguably wasteful, the implication is that while all these recipient
copies are appended to thembox, the bridge should wait until all have
been added before processing. Currently the bridge attempts this by
examining themboxfile size when called, and waiting a small delta
time interval and checking if the size has changed again. It will wait
until the size is stable before continuing. The TL;DR is this could
result in a processing delay.IntroductionThe migration/adoption of Office365 by institutions often poses issues
and problems for users wishing to use different tools for email
transmission, particularly on platforms such as Linux.While it is possible to access various Office365 applications,
particularly Outlook, via a web interface, this is often not sufficient
for several classes of users, particularly those who find the web
interface cumbersome (for instance, the web interface has no (or
limited) support for keyboard shortcuts, it is cumbersome if not
impossible to automate tasks involving event-driven email) and/or for
users who have an existing and efficient email workflow using clients
such asthunderbirdormutt.This small repo houses a small and simple python application with some
supporting documentation that provides a solution to the problem of
sending email from an instituion’s managed domain by leveragingpostfixand somemboxprocessing and then using the CLI toolm365.Method SummaryThe solution requires some seemingly contortuous steps, but in reality
is rather simple and can be summarized as follows:Reading emailReading emails that are locked away in an Outlook server is best
effected by simply adding a forward incoming email rule from your
Institution Outlook Server (IOS) to an externally accessible email
provider (such asgmail), allowing this email to be read easily by
tools such asthunderbirdormutt.┌─────────────────────────────────┐
│IOS that receives incoming email │
└┬────────────────────────────────┘
 │
 └─────┐
       │
      ┌O─────────────────────┐
      │forwardRule(<message>)│
      └┬─────────────────────┘
 ┌─────┘
 │
┌O────┐
│gmail│
└┬────┘
 └─────┐
       │
      ┌O──────────────────────┐
      │clientAccess(<message>)│
      └O──────────────────────┘
 ┌─────┘
 │
┌┴───────────────────────┐
│thunderbird / mutt / etc│
└────────────────────────┘Sending emailThe message is now outside of Outlook, and if the Institution does not
allow non-authorized clients (often this means they only allow Microsoft
tools) to connect to the Outlook server, the following work around will
help. Essentially, the outside client should be configured to send email
using a properly setuppostfixserver that simply copies the target
email to anmboxfile.Thismboxfile is then monitored for any changes, and on a change
(assumed to mean a new email message has been appended), a new process
is fired off to parse off the latest message and then use the command
linem365CLI tool to have the IOS send the email.┌───────────────────────┐
│thundebird / mutt /etc │
└┬──────────────────────┘
 │
 └─────┐
       │
      ┌O────────────────────────────┐
      │sendmail(<message>) (postfix)│
      └┬────────────────────────────┘
 ┌─────┘
 │
┌O────┐
│mbox │
└┬────┘
 └─────┐
       │
      ┌O────────┐
      │mbox2m365│ <--- this repo!
      └┬────────┘
 ┌─────┘
 │
┌O─────────────┐
│m365 <message>│
└┬─────────────┘
 │
┌O────────────────────────────────┐
│IOS that transmits outgoing email│
└─────────────────────────────────┘mbox2m365While all the building blocks to effect the solution exist, the one
missing piece is themboxtom365block, which is provided for by
this rather simple python script.Setup your helper mail server,postfixFirst, installpostfixArchyay-SpostfixUbuntusudoaptinstallpostfixtransportNow, edit thetransportfile.sudobashcd/etc/postfix
cptransporttransport.origecho"* local:rudolph">>transportmain.cfFor themain.cffile, do# Assuming you are still in the /etc/postfix dir in a sudo bash shell...cpmain.cfmain.cf.origecho"mydomain = pangea.net">>main.cfecho"luser_relay = rudolph@pangea.net"echo"transport_maps = hash:/etc/postfix/transport">>main.cfenable/restart the servicessudosystemctlenablepostfix.service
sudosystemctlrestartpostfix.serviceEmail clientSimply configure your email client to use the machine runningpostfixas your email server. All emails will be appended to thetransportuser’smboxfile.Fire upmbox2m365The final piece of the puzzle:cd/var/mail
find.|entrmbox2m365--mboxrudolph--b64_encode\--sendFromFile--cleanUp\--waitForStragglers5-30-