我想從我的Rails應用程序的紅寶石發送郵件,我按照以下步驟:電子郵件是不是在RoR應用程序發送
首先,我用下面的命令來創建郵件:
rails generate mailer UserMailer
我做下面user_mailer.rb
頁:
class UserMailer < ActionMailer::Base
default from: "[email protected]"
def schedule
@mail_to = '[email protected]' #params[:Schedule][:Appointments]
mail :to => @mail_to, :subject => "Hi"
end
end
而且schedule
是我的看法schedule.html.erb
頁:
<%= form_for(:Schedule,:html => {:id => "Schedule"}) do |f| %>
<table class="table" width="100%">
<th><font size="+1">Interview Schedule</font></th>
</table>
<table>
<tr>
<td>
<label style="font-size:small; font-weight:bold;">Send Appointments to:</label>
</td>
<td>
<%= f.text_field :mail_to_address, :style => "font-size:small;" %>
</td>
</tr>
<tr>
<td style="vertical-align:top;">
<label style="font-size:small; font-weight:bold;">Message:</label>
</td>
<td>
<%= f.text_area :message, :style => "font-size:small; width:300px; height:100px;" %>
</td>
</tr>
<tr>
<td>
</td>
<td>
<%= f.submit "Send", { :style => "font-size:small" } %>
</td>
</tr>
</table>
<% end %>
在上面的代碼mail_to_address
text_field我把我想要發送電子郵件,並把一些文字在message
text_field並點擊Send
按鈕的電子郵件地址,但郵件沒有發送。爲什麼?
而且,下面是environment.rb
頁面代碼:
# Load the Rails application.
require File.expand_path('../application', __FILE__)
# Initialize the Rails application.
VideoResume::Application.initialize!
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:authentication => :login,
:charset => 'utf-8',
:user_name => "[email protected]",
:password => "password"
}
,並在我的應用程序/配置/環境/ development.rb我:
VideoResume::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
# Adds additional error checking when serving assets at runtime.
# Checks for improperly declared sprockets dependencies.
# Raises helpful error messages.
config.assets.raise_runtime_errors = true
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
end
請建議我應該怎麼辦,等待回覆。 謝謝
和....會發生什麼,當你嘗試發送電子郵件? – sevenseacat
但它什麼都不做。 – user3800418
您是否在結果操作中調用'UserMailer.schedule.deliver'方法? – mixan946