{"id":902,"date":"2024-02-15T13:35:47","date_gmt":"2024-02-15T12:35:47","guid":{"rendered":"https:\/\/www.homeserver.lu\/?p=902"},"modified":"2024-02-15T13:35:47","modified_gmt":"2024-02-15T12:35:47","slug":"configure-email-service-for-freepbx","status":"publish","type":"post","link":"https:\/\/www.homeserver.lu\/?p=902","title":{"rendered":"Configure email service for FreePBX"},"content":{"rendered":"\n<p>We will configure FreePBX to send emails through a Gmail SMTP relay. FreePBX will use Postfix of the underlying Redhat Linux system to achieve this.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Create a Google app password<\/h2>\n\n\n\n<p>Login to your google account with the email address you want to use for sending the notifications from your FreePBX system. On the Google account management page, click on Security, then on 2-Step-Verification. At the end of that page, create an App Password for your FreePBX system.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Create a password file in CLI<\/h2>\n\n\n\n<p>Create or edit the <em>sasl_passwd<\/em> file:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>sudo nano \/etc\/postfix\/sasl_passwd <\/code><\/pre><\/div>\n\n\n\n<p>Add the following line to it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;smtp.gmail.com]:587 my_email_address@gmail.com:My Google App Password<\/code><\/pre>\n\n\n\n<p>You do not need to worry about the spaces in the app password. Then hash map the password file:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>sudo postmap \/etc\/postfix\/sysl_passwd<\/code><\/pre><\/div>\n\n\n\n<p>After this command ran, you will see a <em>sasl_passwd.db<\/em> file in <em>\/etc\/postfix<\/em>. Permission son this file should be <em>root:root<\/em>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Configure Postfix to use the Gmail relay host<\/h2>\n\n\n\n<p>Add the following lines to the Postfix <em>main.cf<\/em> file:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>sudo nano \/etc\/postfix\/main.cf<\/code><\/pre><\/div>\n\n\n\n<pre class=\"wp-block-code\"><code>myhostname = freepbx.my.domain\nrelayhost = &#91;smtp.gmail.com]:587\n\n#Enable SASL authentication\nsmtp_sasl_auth_enable = yes\n\n#Disallow methods that allow anonymous authentication\nsmtp_sasl_security_options = noanonymous\nsmtp_sasl_tls_security_options = noanonymous\nsmtp_tls_security_level = encrypt\n\n# Location of sasl_passwd\nsmtp_sasl_password_maps = hash:\/etc\/postfix\/sasl_passwd<\/code><\/pre>\n\n\n\n<p>Now restart your postfix service:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>nano systemctl restart postfix<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Test your Postfix installation<\/h2>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>echo &quot;This is a test email&quot; | mail -s &quot;Test mail&quot; destination@email.address<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Optional: force Postfix to rewrite your address<\/h2>\n\n\n\n<p>Sometimes messages are rejected if the from user and the sending user don&#8217;t match up. If this happens, you have to add the following lines to the generic configuration file:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>sudo nano \/etc\/postfix\/generix<\/code><\/pre><\/div>\n\n\n\n<pre class=\"wp-block-code\"><code>root my.sending@email.address \nroot@localhost my.sending@email.address \nroot@localhost.localdomain my.sending@email.address \nroot@freepbx my.sending@email.address \nroot@freepbx.localdomain my.sending@email.address \nasterisk my.sending@email.address \nasterisk@localhost my.sending@email.address \nasterisk@localhost.localdomain my.sending@email.address \nasterisk@freepbx my.sending@email.address \nasterisk@freepbx.localdomain my.sending@email.address\nvm@asterisk my.sending@email.address<\/code><\/pre>\n\n\n\n<p>Hash map the generic file:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>postmap \/etc\/postfix\/generic<\/code><\/pre><\/div>\n\n\n\n<p>You have to add the following line to thew main.cf file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>smtp_generic_maps = hash:\/etc\/postfix\/generic<\/code><\/pre>\n\n\n\n<p>Don&#8217;t forget to restart the Postfix service.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Test your email from FreePBX<\/h2>\n\n\n\n<p>Go to the <em>Admin<\/em> menu, <em>User Manager<\/em> submenu, select the user you want to send an email to and hit the <em>Send Email<\/em> button.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"446\" src=\"https:\/\/www.homeserver.lu\/wp-content\/uploads\/2024\/02\/UserManager-1024x446.png\" alt=\"\" class=\"wp-image-912\" srcset=\"https:\/\/www.homeserver.lu\/wp-content\/uploads\/2024\/02\/UserManager-1024x446.png 1024w, https:\/\/www.homeserver.lu\/wp-content\/uploads\/2024\/02\/UserManager-300x131.png 300w, https:\/\/www.homeserver.lu\/wp-content\/uploads\/2024\/02\/UserManager-768x334.png 768w, https:\/\/www.homeserver.lu\/wp-content\/uploads\/2024\/02\/UserManager-1536x668.png 1536w, https:\/\/www.homeserver.lu\/wp-content\/uploads\/2024\/02\/UserManager-2048x891.png 2048w, https:\/\/www.homeserver.lu\/wp-content\/uploads\/2024\/02\/UserManager-624x272.png 624w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Admin \/ User Manager<\/figcaption><\/figure>\n\n\n\n<p>Don&#8217;t forget to associate an email address to the user.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We will configure FreePBX to send emails through a Gmail SMTP relay. FreePBX will use Postfix of the underlying Redhat Linux system to achieve this. Create a Google app password Login to your google account with the email address you want to use for sending the notifications from your FreePBX system. On the Google account [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[40],"tags":[],"class_list":["post-902","post","type-post","status-publish","format-standard","hentry","category-freepbx"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.homeserver.lu\/index.php?rest_route=\/wp\/v2\/posts\/902","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.homeserver.lu\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.homeserver.lu\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.homeserver.lu\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.homeserver.lu\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=902"}],"version-history":[{"count":11,"href":"https:\/\/www.homeserver.lu\/index.php?rest_route=\/wp\/v2\/posts\/902\/revisions"}],"predecessor-version":[{"id":914,"href":"https:\/\/www.homeserver.lu\/index.php?rest_route=\/wp\/v2\/posts\/902\/revisions\/914"}],"wp:attachment":[{"href":"https:\/\/www.homeserver.lu\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=902"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.homeserver.lu\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=902"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.homeserver.lu\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=902"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}