ruby - 为 Sharetribe 配置 SMTP

标签 ruby ubuntu sendmail sharetribe

我使用了本教程中的 Gmail 设置,效果很好:

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:myemail@gmail.com" "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"

但是我想要一个来自电子邮件而不是 gmail 的品牌。
所以我继续并更改了上面的代码,以便能够使用 SMTP 发送电子邮件:
mail_delivery_method: "smtp"
smtp_email_address: "myuser@example.com"
smtp_email_port: 465
smtp_email_domain: "smtpserver.example.com"
smtp_email_user_name: "myuser@example.com"
smtp_email_password: "mypass"

虽然我尝试了很多东西,但它不起作用。
服务器是 digitalocean VPS,但电子邮件由 DNS 配置中的 hostgator 处理。是的,我的品牌电子邮件适用于 Outlook。
另外这里是防火墙配置:
     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)

以下是一些调试信息,用于查看我尝试发送电子邮件时会发生什么:
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":["mysuser@example.com"],"from":["info@example.com"],"subject":"A new message from the example com team"}}

那么如何使用 SMTP 从品牌域发送电子邮件?

或者我可以跳过所有这些并尝试将 sendmail 配置为使用我的品牌域而不是 gmail?

最佳答案

我正在使用品牌电子邮件。我可以看到端口可能存在的问题。
查看this line

# we have `:enable_starttls_auto => true` and we use 465. It works
smtp_email_port: 465
连同 :enable_starttls_auto => true我们还有:ssl => true在生产中.rb
在我们的案例中,我们使用的是 zoho,因此我们提到了 this documentation

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


请为您的提供商检查此部分。
您可能想尝试非 ssl 的 587 端口。

关于ruby - 为 Sharetribe 配置 SMTP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57305137/

相关文章:

sql - 在 attr_encrypted 列上的 rails 中查询

ruby - dynamic_matchers.rb:55:in `method_missing':ActiveRecord::Base:Class 的未定义方法 `migration_error=' (NoMethodError)

Ruby,捕获字符串的结尾部分

c++ - 使用 ubuntu 终端在 c++ 上运行线程类的问题

eclipse 朱诺 : How to change tab color?

email - 从 bash 邮件中的地址文本设置

ruby - 为什么 "true or true and false"看起来同时为真和假?

sqlite - 找不到参数的方法 compile() [项目 ':react-native-sqlite']

email - 多部分/替代内容类型是否需要内容传输编码?

php - 为什么我在 php 中发送邮件时不接受用户名和密码?