操作邮箱的后缀设置 [英] Postfix Setup for Action Mailbox
问题描述
我按照官方 Ruby on Rails 指南中的说明进行操作.我可以对收到的邮件运行脚本.
I followed the instructions from the offical Ruby on Rails Guide. I can run a script on incoming mail.
但我不知道如何调用 action_mailbox:ingress:postfix 命令.不知何故,我必须切换到工作区,然后运行 bin/rails.是否有将邮件发送到 Rails 的最佳实践?
But I have no clue how to invoke the action_mailbox:ingress:postfix command. Somehow I have to switch into the workspace and then run bin/rails. Is there some best practice for sending the mail to rails?
推荐答案
您可以按照以下步骤在生产服务器中使用操作邮箱配置postfix:
You can follow the steps to configure postfix with action mailbox in production server:
第一步:创建bash脚本
Step 1: Create bash script
在 /usr/local/bin/
中创建一个脚本,将所有收到的电子邮件转发到我们的 Rails 应用程序:
Create a script inside /usr/local/bin/
to forward all incoming emails to our rails app:
$ nano email_forwarder.sh
在脚本中添加以下内容:
Add following to the script:
#!/bin/sh
export HOME=YOUR_HOME_PATH
export PATH=YOUR_PATH
export RBENV_ROOT=YOUR_RBENV_PATH
cd /path/to/your/project && bin/rails action_mailbox:ingress:postfix URL='https://truemark.com.np/rails/action_mailbox/relay/inbound_emails' INGRESS_PASSWORD='YOUR_INGRESS_PASSWORD'
替换HOME
、PATH
、RBENV_ROOT
、URL
和INGRESS_PASSWORD
的值如下所述:
Replace value of HOME
, PATH
, RBENV_ROOT
, URL
and INGRESS_PASSWORD
as described below:
- 复制
HOME
的主目录
$ cd
$ pwd
- 复制您从 $PATH 获得的内容以及分别用于 PATH 和 RBENV_PATH 的 rbenv 命令
$ $PATH
$ which rbenv
复制您添加到
credentials
或ENV
/application.yml
文件中的密码,用于INGRESS_PASSWORD
Copy the password you added to
credentials
or yourENV
/application.yml
file forINGRESS_PASSWORD
对于 URL,如果您的应用程序位于 https://example.com,则完整命令将看起来像这样:
For URL, if your application lived at https://example.com, the full command would look like this:
bin/rails action_mailbox:ingress:postfix URL='https://example.com/rails/action_mailbox/relay/inbound_emails' INGRESS_PASSWORD='YOUR_STRONG_PASSWORD'
第 2 步:配置 Postfix 以将收到的电子邮件通过管道传输到脚本
Step 2: Configure Postfix to Pipe Incoming emails to script
- 创建
/etc/postfix/virtual_aliases
以添加一个通用别名;localuser 必须是现有的本地用户:
- Create
/etc/postfix/virtual_aliases
to add a catch-all alias; localuser needs to be an existing local user:
# /etc/postfix/virtual_aliases @mydomain.tld localuser@mydomain.tld
- 创建
/etc/postfix/transport
以添加传输映射.forward_to_rails 可以随心所欲;稍后将在master.cf
中使用
- Create
/etc/postfix/transport
to add a transport mapping. forward_to_rails can be whatever you want; it will be used later inmaster.cf
# /etc/postfix/transport mydomain.tld forward_to_rails:
- 接下来,
transport
和virtual_aliases
都需要编译成 berkeley db 文件: - Next, both
transport
andvirtual_aliases
need to be compiled into berkeley db files:
$ sudo postmap /etc/postfix/virtual_aliases $ sudo postmap /etc/postfix/transport
- 将传输添加到
/etc/postfix/master.cf
# /etc/postfix/master.cf forward_to_rails unix - n n - - pipe flags=Xhq user=deploy:deploy argv=/usr/local/bin/email_forwarder.sh ${nexthop} ${user}
我们应该指定用户,以便脚本由该用户运行,而不是 postfix 或 nobody.
user=deploy:deploy
~user=user:group
We should specify user so script is run by that user and not postfix or nobody.
user=deploy:deploy
~user=user:group
- 在
/etc/postfix/main.cf
中添加以下内容
- Add following in
/etc/postfix/main.cf
# /etc/postfix/main.cf transport_maps = hash:/etc/postfix/transport virtual_alias_maps = hash:/etc/postfix/virtual_aliases
您可以使用
tail -f/var/log/mail.log
查看 postfix 日志.You can view postfix log with
tail -f /var/log/mail.log
.大功告成!您现在应该可以在您的操作邮箱中收到电子邮件.
And done! You should be able to receive the email now in you action mailbox.
您可以在此处详细了解解决方案:https://thedevpost.com/blog/setup-action-mailbox-with-postfix-part-2/
You can read about the solution in detail here: https://thedevpost.com/blog/setup-action-mailbox-with-postfix-part-2/
关于在开发中设置操作邮箱和测试,您可以在此处详细阅读:https://thedevpost.com/blog/setup-action-mailbox-with-postfix-part-1/
For setting up action mailbox and testing in development, you can read about it in detail here: https://thedevpost.com/blog/setup-action-mailbox-with-postfix-part-1/
这篇关于操作邮箱的后缀设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- 创建