简体   繁体   English

如何使用Spree在开发中发送电子邮件

[英]How to Send Email in Development with Spree

I'm in the development environment and I want to send out test emails via my console. 我在开发环境中,我想通过我的控制台发送测试电子邮件。 I got the console going nice, but its not sending. 我让控制台运行良好,但它没有发送。

I go to Spree's Mail Method Settings and here's what I got: 我去Spree的邮件方法设置,这是我得到的:

BenMorganIO的狂欢邮件方法设置

I've double checked the password. 我已经仔细检查了密码。 I've Googled the hell out of it. 我用谷歌搜索了它。 I can't figure out how to get this thing to work. 我无法弄清楚如何使这个东西工作。

Key Question: How does one get email working in Spree from the development environment? 关键问题:如何从开发环境中获取Spree中的电子邮件?

Things I Tried : Spree Mail Method is not working? 我尝试的事情狂欢邮件方法不起作用?

The problem is that you need a local email server that can receive your emails. 问题是您需要一个可以接收电子邮件的本地电子邮件服务器。 To test the setup in development install the mailcatcher gem, that you will use as a SMTP server in development, catching all incoming mails and displaying them on http://localhost:1080/: 要在开发中测试设置,请安装mailcatcher gem,您将在开发中将其用作SMTP服务器,捕获所有传入的邮件并在http://localhost:1080/:上显示它们http://localhost:1080/:

Just run in the terminal 跑到终点站

gem install mailcatcher gem安装mailcatcher

then run mailcatcher in the console. 然后在控制台中运行mailcatcher A toy SMTP server will be running on port 1025 catching emails and displaing them on HTTP port 1080. 玩具SMTP服务器将在端口1025上运行,捕获电子邮件并在HTTP端口1080上替换它们。

Then just goto the spree admin panel and configure it. 然后只需转到spree管理面板并进行配置。 The following settings work perfectly for me without any code writing. 以下设置对我来说非常有效,无需任何代码编写。

在此输入图像描述

After I clicked on send test mail I got the following email on my localhost: 点击send test mail我在本地主机上收到了以下电子邮件:

在此输入图像描述

Spree actually overrides the ActionMailer settings with the settings input in the graphical interface using the Spree::MailMethod class. Spree实际上使用Spree :: MailMethod类使用图形界面中的设置输入覆盖ActionMailer设置。 On the plus side, you can set things in the admin interface, with a downside of several unexpected behaviours. 从好的方面来说,您可以在管理界面中设置内容,但有一些意外行为的缺点。

We maintain many Spree stores and we always run with the settings: 我们维护许多Spree商店,我们总是使用以下设置运行:

Spree.config do |config|
  config.override_actionmailer_config = false
  config.mails_from = "no-reply@yourdomain.com"
end

This will allow you to configure ActionMailer as you would in any other Rails application: http://guides.rubyonrails.org/action_mailer_basics.html#example-action-mailer-configuration 这将允许您像在任何其他Rails应用程序中一样配置ActionMailer: http//guides.rubyonrails.org/action_mailer_basics.html#example-action-mailer-configuration

This is being adopted as standard procedure for the next release of Spree after 2.2.x. 这是在2.2.x之后下一版Spree的标准程序。

https://github.com/spree/spree/pull/4377 has extracted the web configuration to its own gem to maintain backwards compatibility. https://github.com/spree/spree/pull/4377已将Web配置解压缩到自己的gem,以保持向后兼容性。

Spree commerce use ActionMailer to send emails. 狂欢商务使用ActionMailer发送电子邮件。 If you want send emails in development mode, you should enable delivery_method in config/enviranments/development.rb file. 如果要在开发模式下发送电子邮件,则应在config/enviranments/development.rb文件中启用delivery_method

Just set this variable config.action_mailer.delivery_method = :smtp 只需设置此变量config.action_mailer.delivery_method = :smtp

This problem arises because you don't have a local email server to receive your emails. 出现此问题的原因是您没有本地电子邮件服务器来接收电子邮件。

Step 1: The first step would be to Install the mailcatcher gem in order to test the setup in development. 步骤1:第一步是安装mailcatcher gem以测试开发中的设置。

You will be using it as a SMTP server to catch all the incoming mails and display them on http://localhost:1080/ : 您将使用它作为SMTP服务器来捕获所有传入的邮件并在http:// localhost:1080 /上显示它们:

Step 2: Just run in the terminal “ gem install mailcatcher ” in the console. 第2步:在控制台中运行终端“ gem install mailcatcher ”。

You will find an SMTP server running on port 1025 catching emails and displaying them on HTTP port 1080 您将在端口1025上运行SMTP服务器,捕获电子邮件并在HTTP端口1080上显示它们

Step 3: You will find an SMTP server running on port 1025 catching emails and displaying them on HTTP port 1080 步骤3:您将在端口1025上运行一个SMTP服务器,捕获电子邮件并在HTTP端口1080上显示它们

Add line: gem 'spree_mail_settings', github: 'spree-contrib/spree_mail_settings', branch: 'master' 添加行: gem'spree_mail_settings',github:'spree-contrib / spree_mail_settings',分支:'master'

Then run: bundle 然后运行: bundle

Step 4: Further, go to “Spree admin panel” and configure it. 步骤4:进一步,转到“Spree管理面板”并进行配置。 These settings will work perfectly for you without any code writing. 无需任何代码编写,这些设置将完美适合您。

Then click on “ Send test mail 然后单击“ 发送测试邮件

Step 5: 第5步:

You will receive the an email on your local host. 您将在本地主机上收到一封电子邮件。

Now your problem is solved. 现在你的问题解决了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM