[GTALUG] Fetchmail and Office365 and backslashes, oh my!

Peter King peter.king at utoronto.ca
Sun Jul 15 23:42:12 EDT 2018


For those who might be interested, here's the working getmailrc
configuration I'm using successfully with Office365 (suitably
anonymized):

.getmail/getmailrc:

  [options]
  delete = true
  message_log = ~/.getmail/log
  message_log_verbose = true

  [retriever]
  type = SimpleIMAPSSLRetriever
  server = outlook.office365.com
  username = PERSONAL_EMAIL at utoronto.ca\SHARED_MAILBOX at utoronto.ca
  port = 993
  password = PASSWORD

  [destination]
  type = MDA_external
  path = /usr/bin/procmail
  unixfrom = True


That's the complete file.  Here's what seems to be going on.

The first stanza, [options], gives global instructions to getmail.
Here, the first, delete = true, just deletes the messages off the
O365 server after it retrieves them.  The next two lines specify
where getmail should write its log messagees, and that they should
contain a certain amount of detail.

The second stanza, [retriever], tells getmail which account to try
to get the email from.  Note that there is only a single account
listed.  That's a feature, not a bug, of getmail.  If you want to
get email from several accounts, you need to use several distinct
getmailrc configuration files (each uniquely titled), and then run
through them all -- a simple shell script will do that.  Anyway,
here the type variable says that I'm picking email up from an IMAP
server using SSL; the server variable gives the address of the
server.  The form of the username here, with the personal email
address + backslash + address of the shared email account, is where
getmail succeeds in the case fetchmail failed -- for whatever reason
getmail passes that on to the O365 server in a way that it parses
correctly.  (It seems that all "shared mailboxes" in O365 are in 
fact something like aliased subirectories under a personal account
for reasons I don't understand.)  The next two are obvious: the port
gives the port, and fill in your password next.

The last stanza, [destination], describes what getmail should do with
the email.  Here I have it set to hand the email off to procmail for
sorting: type = MDA_external tells getmail to hand over the email to
a distinct mail delivery agent; the value of path tells getmail where
to find the MDA.  The unixfrom = true tells getmail that it can expect
the emails to begin in proper *NIX fashion with a From: line.

In case anyone is interested, here's the relevant bit of procmail
configuration, from .procmailrc:

  # Define variables
  MAILDIR=$HOME/Mail
  DEFAULT=$MAILDIR/NEWMAIL
  LOGFILE=$HOME/.procmaillog
  #
  :0:
  * ^To.*SHARED_MAILBOX at utoronto.ca
  $HOME/Mail/DESTINATION_MAILBOX

The variables just configure my local setup; the line ":0:" is a magic
incantation that tells procmail not to keep a copy once it carries out
the instructions in the next two lines; the first looks for any email
where the address (To:) header is the SHARED_MAILBOX, and the last line
tells it to write that email into the mailbox DESTINATION_MAILBOX.

On my first test pass, I had getmail deliver the mail directly to its
destination, so the whole stanza looked like this:

  [destination]
  type = Mboxrd
  path = ~/Mail/DESTINATION_MAILBOX

Here the first line declares that the email is heading for a mailbox
in mbox format, and the second line that the mailbox is as before the
DESTINATION_MAILBOX found at ~/Mail/.

So far, Things Just Work.  Since getmail gets the mail, I assume it
passes the relevant SSL tests.  I'll have to learn some more to make
sure it is using, or at least is able to use, fingerprint validation.
Right now I'm testing and running getmail manually, but I expect to
make it just an ordinary cron job once I learn enough to be confident
that everything works properly.

-- 
Peter King			 	peter.king at utoronto.ca
Department of Philosophy
170 St. George Street #521
The University of Toronto		   (416)-978-3311 dept
Toronto, ON  M5R 2M8
       CANADA

http://individual.utoronto.ca/pking/

=========================================================================
GPG keyID 0x7587EC42 (2B14 A355 46BC 2A16 D0BC  36F5 1FE6 D32A 7587 EC42)
gpg --keyserver pgp.mit.edu --recv-keys 7587EC42
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <http://gtalug.org/pipermail/talk/attachments/20180715/84cea882/attachment.sig>


More information about the talk mailing list