Tarik
Tarik

Reputation: 4546

Configure SMTP for Sharetribe

I used this Gmail setup from this tutorial and it works well:

Tutorial: https://freedif.org/how-to-install-sharetribe-for-ubuntu-16-04

# Email configurations: (Sendmail + Gmail)
Login to your gmail account, enable imap.
Let the access here first: https://www.google.com/settings/security/lesssecureapps
Go to: https://accounts.google.com/b/0/DisplayUnlockCaptcha

sudo apt-get install sendmail mailutils sendmail-bin

folder and configuration file::
    sudo mkdir -m 700 /etc/mail/authinfo/
    sudo su
    cd /etc/mail/authinfo/
    sudo nano gmail-auth
        AuthInfo: "U:root" "I:[email protected]" "P:mypass"
the hash map:
    sudo makemap hash gmail-auth < gmail-auth
configure your sendmail:
    sudo nano /etc/mail/sendmail.mc
        paste just before the first MAILER definition line: (` and ' inconsistency is OK!)
            define(`SMART_HOST',`[smtp.gmail.com]')dnl
            define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl
            define(`ESMTP_MAILER_ARGS', `TCP $h 587')dnl
            define(`confAUTH_OPTIONS', `A p')dnl
            TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
            define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
            FEATURE(`authinfo',`hash -o /etc/mail/authinfo/gmail-auth.db')dnl
Now rebuild the sendmail configuration and restart it:
    make -C /etc/mail
    restart sendmail

Configure Sharetribe to use Sendmail:
    exit root user CTRL+D
    nano ~/sharetribe/config/config.yml
        mail_delivery_method: "sendmail"

However I want a branded from email instead of a gmail. So I go ahead and changed the above code to be able to send email using the SMTP:

mail_delivery_method: "smtp"
smtp_email_address: "[email protected]"
smtp_email_port: 465
smtp_email_domain: "smtpserver.example.com"
smtp_email_user_name: "[email protected]"
smtp_email_password: "mypass"

Although I tried a lot of things, it does not work. Server is a digitalocean VPS but emails are handled by hostgator from DNS configuration. Yes I my branded email works fine with outlook. Also here is the firewall configuration:

     To                         Action      From
     --                         ------      ----
[ 1] OpenSSH                    ALLOW IN    Anywhere
[ 2] Apache Full                ALLOW IN    Anywhere
[ 3] 11211                      ALLOW IN    Anywhere
[ 4] 25                         ALLOW IN    Anywhere
[ 5] 465                        ALLOW IN    Anywhere
[ 6] 587                        ALLOW IN    Anywhere
[ 7] OpenSSH (v6)               ALLOW IN    Anywhere (v6)
[ 8] Apache Full (v6)           ALLOW IN    Anywhere (v6)
[ 9] 11211 (v6)                 ALLOW IN    Anywhere (v6)
[10] 25 (v6)                    ALLOW IN    Anywhere (v6)
[11] 465 (v6)                   ALLOW IN    Anywhere (v6)
[12] 587 (v6)                   ALLOW IN    Anywhere (v6)

Here is some debug information to see what happens when I try to send the email:

mysuser@example:~/sharetribe$ RAILS_ENV=production rake jobs:work


[Worker(host:example.com pid:2407)] Starting job worker
2019-07-31T13:42:52-0700: [Worker(host:example.com pid:2407)] Starting job worker
[Worker(host:example.com pid:2407)] Job CreateMemberEmailBatchJob (id=1) (queue=default) RUNNING
2019-07-31T13:43:12-0700: [Worker(host:example.com pid:2407)] Job CreateMemberEmailBatchJob (id=1) (queue=default) RUNNING
{"tag":"delayed_job","free":"Running job","type":"running","structured":{"job_name":"CreateMemberEmailBatchJob","args":{"sender_id":"123","community_id":1,"content":"123123","locale":"any","mode":"all_users"}}}
{"tag":"delayed_job","free":"Job success","type":"success","structured":{"job_name":"CreateMemberEmailBatchJob","args":{"sender_id":"123","community_id":1,"content":"123123","locale":"any","mode":"all_users"}}}
[Worker(host:example.com pid:2407)] Job CreateMemberEmailBatchJob (id=1) (queue=default) COMPLETED after 0.7504
2019-07-31T13:43:13-0700: [Worker(host:example.com pid:2407)] Job CreateMemberEmailBatchJob (id=1) (queue=default) COMPLETED after 0.7504
[Worker(host:example.com pid:2407)] Job CommunityMemberEmailSentJob (id=2) (queue=default) RUNNING
2019-07-31T13:43:13-0700: [Worker(host:example.com pid:2407)] Job CommunityMemberEmailSentJob (id=2) (queue=default) RUNNING
{"tag":"delayed_job","free":"Running job","type":"running","structured":{"job_name":"CommunityMemberEmailSentJob","args":{"sender_id":"123","recipient_id":"123","community_id":1,"content":"123123","locale":"any","test_to_yourself":null}}}

127.0.0.1:11211 failed (count: 0) Errno::ECONNREFUSED: Connection refused - connect(2) for "127.0.0.1" port 11211
DalliError: No server available
127.0.0.1:11211 failed (count: 1) Errno::ECONNREFUSED: Connection refused - connect(2) for "127.0.0.1" port 11211
127.0.0.1:11211 is down


DalliError: No server available
{"tag":"action_mailer","free":"Delivering email","type":"delivering_email","structured":{"to":["[email protected]"],"from":["[email protected]"],"subject":"A new message from the example com team"}}

So how can I send email from branded domain using SMTP?

Or can I skip all this and try to configure sendmail to use my branded domain instead of gmail?

Upvotes: 2

Views: 302

Answers (1)

Anand Bait
Anand Bait

Reputation: 371

I am using branded email. I could see possible issue with port. Check this line

# we have `:enable_starttls_auto => true` and we use 465. It works
smtp_email_port: 465

Along with :enable_starttls_auto => true we also have :ssl => true in production.rb

In our case we were using zoho hence we referred this documentation

Outgoing Server Name: smtp.zoho.in
Port: 465 with SSL or
Port: 587 with TLS

Please check this part for your provider. You might want to try for 587 port for non-ssl.

Upvotes: 0

Related Questions