title: Postfix with office365 integration for sending emails
body: <p>I have a CentOS7 server that will be deployed to a customer site. I want to get alerts via emails when something goes wrong on the server.</p>
  
  <p>I have an office365 account so I am thinking whether I can use it as a SMTP relay server. (Forgive me here if my words don't make sense since I have very limited knowledge about SMTP and email related technology). </p>
  
  <p>My first question is, do I need to do anything special with the office365 account? I am using smtp.office365.com:587 as the SMTP relay host.</p>
  
  <p>Here is my postfix main.cf config:</p>
  
  <pre><code>relayhost = [smtp.office365.com]:587
  smtp_always_send_ehlo = yes
  smtp_sasl_auth_enable = yes
  smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
  smtp_generic_maps = hash:/etc/postfix/generic
  smtp_tls_security_level = may
  smtp_sasl_security_options = noanonymous
  </code></pre>
  
  <p>Here is my "generic" and "sasl_passwd" file look like. I also used the "postmap" to generate the .db file</p>
  
  <pre><code>/.*/    &lt;o365 email&gt;
  root@server.difan.local &lt;o365 email&gt;
  root@localdomain        &lt;o365 email&gt;
  @localdomain            &lt;o365 email&gt;
  
  [smtp.office365.com]:587 &lt;o365 email&gt;:&lt;o365 password&gt;
  </code></pre>
  
  <p>This is the command I used to test it</p>
  
  <pre><code>echo "This is the body of the email" | mail -s "This is the subject line"   difan.zhao@outlook.com
  </code></pre>
  
  <p>Here is what I see in /var/log/maillog</p>
  
  <pre><code>Mar 26 10:46:00 server postfix/pickup[1921]: 5DC594087202: uid=0 from=&lt;root&gt;
  Mar 26 10:46:00 server postfix/cleanup[2495]: 5DC594087202: message-id=&lt;20170326164600.5DC594087202@server.difan.local&gt;
  Mar 26 10:46:00 server postfix/qmgr[1922]: 5DC594087202: from=&lt;root@server.difan.local&gt;, size=486, nrcpt=1 (queue active)
  Mar 26 10:46:00 server postfix/smtp[2497]: warning: SASL authentication failure: No worthy mechs found
  Mar 26 10:46:00 server postfix/smtp[2497]: 5DC594087202: SASL authentication failed; cannot authenticate to server smtp.office365.com[40.97.128.34]: no mechanism available
  ... &lt;last two messages repeated 4 times&gt;
  Mar 26 10:46:02 server postfix/smtp[2497]: 5DC594087202: to=&lt;difan.zhao@outlook.com&gt;, relay=smtp.office365.com[40.97.142.194]:587, delay=2.2, delays=0.02/0/2.2/0, dsn=4.7.0, status=deferred (SASL authentication failed; cannot authenticate to server smtp.office365.com[40.97.142.194]: no mechanism available)
  </code></pre>
  
  <p>Where did I do wrong here? Thanks!</p>