Accessing the WSU Mail Server
Contents
Generating a Token
Download and run the token generator software. Note that you should always check any code that others have written before running it.
git clone https://github.com/UvA-FNWI/M365-IMAP cd M365-IMAP pip install msal python3 get_token.py
When running the python script, a Web browser will open and ask for your Office365 credientials (WSU ID and password). This is sent to Office365 for verification before generating the token. Once authenticated, the Refresh and Access tokens are saved in
- imap_smtp_refresh_token
- imap_smtp_access_token
The Refresh Token needs to be inserted into the OfflineIMAP configuration file below.
Downloading Email using IMAPS
IMAPS is an open standard for email access, so there are many programs that can be used for IMAPS access. Here we show how to sync mail using OfflineIMAP.
If using OSX, OfflineIMAP can be installed using MacPorts or any other package manager.
Configuring OfflineIMAP
Before running OfflineIMAP, it must be configured by editing the file .offlineimaprc. Below is a sample configuration file.
[general] accounts = westernsydney.edu.au ui = ttyui autorefresh = 2 quick = 10 [Account westernsydney.edu.au] localrepository = LocalWSU remoterepository = RemoteWSU [Repository LocalWSU] type = Maildir localfolders = ~/Mail # make sure this directory exists [Repository RemoteWSU] type = IMAP sslcacertfile =/opt/local/share/curl/curl-ca-bundle.crt remotehost = outlook.office365.com remoteuser = staffid@westernsydney.edu.au auth_mechanisms = XOAUTH2 oauth2_request_url = https://login.microsoftonline.com/common/oauth2/v2.0/token # use Thunderbird credentials oauth2_client_id = 08162f7c-0fd2-4200-a84a-f25a4db0b584 oauth2_client_secret = TxRBilcHdC6WGBee]fs?QR:SJ8nI[g82 oauth2_refresh_token = # add token obtained from script. folderfilter = lambda folder: not folder.startswith('Calendar') and not folder.startswith('Contacts')
Once configured, run offlineimap and your email will be synced from the Office365 server to you local ~/Mail directory. Note that the local mail will be stored as in MailDir format.
Sending Email using SMTPS
Configuring MSMTP
# default settings defaults logfile ~/.msmtp.log port 587 tls on tls_trust_file /opt/local/share/curl/curl-ca-bundle.crt account wsu host smtp.office365.com port 587 auth xoauth2 tls on tls_starttls on from email@westernsydney.edu.au user staffid@westernsydney.edu.au passwordeval "cd /pathto/M365-IMAP/; python3 refresh_token.py" # Set a default account account default : wsu
An email client must be set up to use msmtp to deliver email.
If using an emacs based mail client add these lines to your .emacs file.
(setq message-send-mail-function 'message-send-mail-with-sendmail) (setq sendmail-program "/opt/local/bin/msmtp") (setq mail-host-address "westernsydney.edu.au") (setq user-full-name "Fred Savage") (setq user-mail-address "fred.savage@westernsydney.edu.au")
More options are here https://www.emacswiki.org/emacs/GnusMSMTP.