{"id":2587,"date":"2020-08-03T14:37:01","date_gmt":"2020-08-03T13:37:01","guid":{"rendered":"https:\/\/www.cyber-cottage.eu\/?p=2587"},"modified":"2020-10-12T12:57:55","modified_gmt":"2020-10-12T11:57:55","slug":"setting-up-postfix-to-use-office-365-mail","status":"publish","type":"post","link":"https:\/\/www.cyber-cottage.co.uk\/?p=2587","title":{"rendered":"Setting up Postfix to use Office 365 mail"},"content":{"rendered":"\n<p>FreePBX uses centos 7 and postfix fom its mail delivery, normally this is fine unless the customer is using  Office 365 mail then there can be delivery issues.<\/p>\n\n\n\n<p>Firstly you will need to set up a user in Office 365 for the system.<\/p>\n\n\n\n<p>Postfix&#8217;s main configuration file is main.cf and that is where we make the required change as follow:<\/p>\n\n\n\n<p>[root@localhost ~]# vi \/etc\/postfix\/main.cf<\/p>\n\n\n\n<p>Append the following lines<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">masquerade_domains = domainname\nmyhostname = USERNAME.domainname\nmydomain = USERNAME.domainname\nmyorigin = USERNAME@domainname\nrelayhost = [smtp.office365.com]:587\n\nmynetworks = 127.0.0.0\/8\ninet_interfaces = loopback-only\nsmtp_use_tls = yes\nsmtp_always_send_ehlo = yes\nsmtp_sasl_auth_enable = yes\nsmtp_sasl_password_maps = hash:\/etc\/postfix\/sasl_passwd\nsmtp_sasl_security_options = noanonymous\nsmtp_sasl_tls_security_options = noanonymous\nsmtp_tls_security_level = encrypt\nsmtp_generic_maps = hash:\/etc\/postfix\/generic \n# smtp_tls_CAfile = \/etc\/ssl\/certs\/ca-certificates.crt<\/pre>\n\n\n\n<p>Save and exit from the file.<br>Next we need to edit the configuration for the postfix SASL credentials:<\/p>\n\n\n\n<p>[root@localhost ~]# vi \/etc\/postfix\/sasl_passwd<\/p>\n\n\n\n<p>Add a line below<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[smtp.office365.com]:587 user@domainname:password<\/pre>\n\n\n\n<p>Replacing  <strong>user@domainname:password<\/strong> with your sender account details<\/p>\n\n\n\n<p>Save and exit from file<\/p>\n\n\n\n<p>A Postfix lookup table must now be generated from the sasl_passwd text file by running the following command.<\/p>\n\n\n\n<p>[root@localhost ~]# postmap \/etc\/postfix\/sasl_passwd<\/p>\n\n\n\n<p>Now change permission for this file<\/p>\n\n\n\n<p>[root@localhost ~]# chown root:postfix \/etc\/postfix\/sasl_passwd<\/p>\n\n\n\n<p>[root@localhost ~]# chmod 640 \/etc\/postfix\/sasl_passwd<\/p>\n\n\n\n<p>Next, we need to configure generic file in order to be able to send emails as a valid user (this is required for Office365).<\/p>\n\n\n\n<p>[root@localhost ~]# vi \/etc\/postfix\/generic<\/p>\n\n\n\n<p>Go the end of file and append following lines.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">root@localhost.localdomain UserName@Domain.com<\/pre>\n\n\n\n<p>Again replacing  <strong>localhost.localdomain<\/strong> and <strong>UserName@Domain.com<\/strong> with your service hostname and the email user are using<\/p>\n\n\n\n<p>Save and exit from file.<\/p>\n\n\n\n<p>Next let&#8217;s correct the file permission.<\/p>\n\n\n\n<p>[root@localhost ~]# chown root:root \/etc\/postfix\/generic<\/p>\n\n\n\n<p>[root@localhost ~]# chmod 0600 \/etc\/postfix\/generic<\/p>\n\n\n\n<p>[root@localhost ~]# postmap \/etc\/postfix\/generic<\/p>\n\n\n\n<p>Now restart Postfix service.<\/p>\n\n\n\n<p>[root@localhost ~]# systemctl restart postfix<\/p>\n\n\n\n<p>Now try to send a test email using the command below:<br>FOR Centos:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">echo \"This is the body of the email\"| mail -r\"Sender-Display-Name&lt;<a href=\"mailto:sender@domain.com\">sender@domain.com<\/a>>\" -s \"This is the subject(E-Mail from SMTP Relay) line\" recipeat@gmail.com<\/pre>\n\n\n\n<p>In FreePBX under Voicemail admin you must change the senders address to match your account as well as the sender for notifications such as backups etc. otherwise you can get errors and mail wont be delivered.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>FreePBX uses centos 7 and postfix fom its mail delivery, normally this is fine unless the customer is using Office 365 mail then there can be delivery issues. Firstly you will need to set up a user in Office 365 for the system. Postfix&#8217;s main configuration file is main.cf and that is where we make [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2563,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"content-type":"","advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[11],"tags":[27,40,51,208,209,207,199,64,117,76],"class_list":["post-2587","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-knowledge","tag-centos","tag-freepbx","tag-linux","tag-mail","tag-microsoft","tag-office365","tag-pbxact","tag-postfix","tag-sangoma","tag-voip"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.cyber-cottage.co.uk\/wp-content\/uploads\/2019\/03\/call-rec.png?fit=100%2C100&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p5daZy-FJ","jetpack_sharing_enabled":true,"jetpack_likes_enabled":false,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/2587","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2587"}],"version-history":[{"count":4,"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/2587\/revisions"}],"predecessor-version":[{"id":2666,"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/2587\/revisions\/2666"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=\/wp\/v2\/media\/2563"}],"wp:attachment":[{"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2587"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2587"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cyber-cottage.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2587"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}