chatwoot / docs

Official docs, handbook for Chatwoot
https://www.chatwoot.com/help-center
MIT License
43 stars 141 forks source link

doc: Email channel using postfix #175

Open sojan-official opened 2 years ago

sojan-official commented 2 years ago

Creating documentation on how to set up a self-hosted chatwoot, where the email channel works with postfix

sojan-official commented 1 year ago

ref: https://discord.com/channels/647412545203994635/1063240028542742638/1065627261040070697

Yes shure @softcrew

Fisrt you have to install Postfix as it says on the instructions:

sudo apt install -y postfix

Make shure that you configure the certificates as you have on chatwoot( in the file /etc/postfix/main.cf:

smtpd_tls_cert_file = /etc/letsencrypt/live/YOUR_DOMAIN_CERT_FOLDER/fullchain.pem
smtpd_tls_key_file = /etc/letsencrypt/live/YOUR_DOMAIN_CERT_FOLDER/privkey.pem
smtpd_tls_security_level=may

smtp_tls_CApath=/etc/letsencrypt/live/YYOUR_DOMAIN_CERT_FOLDER/

Then, this is how i set the postfix conf:

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

# See http://www.postfix.org/COMPATIBILITY_README.html -- default to 2 on
# fresh installs.
compatibility_level = 2

# TLS parameters
smtpd_tls_cert_file = /etc/letsencrypt/live/YOUR_DOMAIN_CERT_FOLDER/fullchain.pem
smtpd_tls_key_file = /etc/letsencrypt/live/YOUR_DOMAIN_CERT_FOLDER/privkey.pem
smtpd_tls_security_level=may

smtp_tls_CApath=/etc/letsencrypt/live/YOUR_DOMAIN_CERT_FOLDER/
smtp_tls_security_level=may
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname =YOUR_DOMAIN
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = $myhostname, YOUR_DOMAIN, SRV_NAME, localhost.localdomain, localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all
virtual_alias_domains = $mydomain
#virtual_alias_maps = hash:/etc/postfix/virtual
local_recipients_maps =
transport_maps = hash:/etc/postfix/transport
virtual_alias_maps = hash:/etc/postfix/virtual_aliases

And restart postfix Then, you need to configure this ENV_variables to work:

SMTP_DOMAIN=YOUR_DOMAIN
SMTP_ADDRESS=localhost
SMTP_PORT=25
#SMTP_USERNAME=
#SMTP_PASSWORD=
SMTP_ENABLE_STARTTLS_AUTO=true
SMTP_OPENSSL_VERIFY_MODE=none
MAILER_INBOUND_EMAIL_DOMAIN=YOUR_DOMAIN
RAILS_INBOUND_EMAIL_SERVICE=relay
RAILS_INBOUND_EMAIL_PASSWORD=YOUR_PASSWORD

And restart the chatwoot service

Then - extracted from https://thedevpost.com/blog/setup-action-mailbox-with-postfix-part-2/ - i did this:

Create /etc/postfix/virtual_aliases to add a catch-all alias; localuser needs to be an existing local user (for example chatwoot :

vi /etc/postfix/virtual_aliases

@YOUR_DOMAIN chatwoot@YOUR_DOMAIN Create /etc/postfix/transport to add a transport mapping. “forward_to_rails” can be whatever you want; it will be used later in master.cf

vi  /etc/postfix/transport

YOUR_DOMAIN forward_to_rails:

Next, both transport and virtual_aliases need to be compiled into berkeley DB files:

$ sudo postmap /etc/postfix/virtual_aliases
$ sudo postmap /etc/postfix/transport
# Add the transport to /etc/postfix/master.cf
vi  /etc/postfix/master.cf
mytransportname   unix  -       n       n       -       -       pipe
  flags=Xhq user=chatwoot:chatwoot argv=/home/chatwoot/chatwoot/bin/import_mail_to_chatwoot
  ${nexthop} ${user}

then you need to create the script /home/chatwoot/chatwoot/bin/import_mail_to_chatwoot whit this:

INGRESS_PASSWORD= same as you put in the env file
URL=http://localhost:3000/rails/action_mailbox/relay/inbound_emails
curl -sS -u "actionmailbox:$INGRESS_PASSWORD" \
 -A "Action Mailbox curl relayer" \
 -H "Content-Type: message/rfc822" \
 --data-binary @- \
 $URL
~

Then restart postfix again!

Let me know if was clear and it worked!

movilreup commented 1 year ago

Hello @sojan-official i need a help i try to get this tutorial but is for Ubuntu right? What is the chatwoot routes to configure on docker because i try to see this routes on docker and no see the sames routes to configure Postfix on docker. Thanks i hope u respond