我們在生產應用程序中使用SendGrid,它工作正常。我們最近試圖在開發中測試新的功能/電子郵件,但似乎無法獲得發送的電子郵件。任何想法我們會出錯?我們在生產中使用了類似的功能,我們也遵循SendGrid的實施指南。感覺就像我錯過了簡單的事情!Rails來自開發環境的SendGrid電子郵件
首先我導出SENDGRID_USERNAME
和SENDGRID_PASSWORD
和踢它加入到我的.bash_profile
export SENDGRID_USERNAME=xxxxxxx
export SENDGRID_PASSWORD=xxxxxxx
我已經證實了這些存在,是正確的控制檯。
創建一個developer_email.html.erb
文件:
<p>Hi! Sendgrid test</p>
而且一個DeveloperMailer
文件:
class DeveloperMailer < ActionMailer::Base
default from: "[email protected]"
def developer_email(developer_id)
@recipients = ["[email protected]"]
mail(to: @recipients, subject: 'Does sendgrid work?')
end
end
更新了development.rb
文件:
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.sendgrid.net',
port: '587',
domain: 'localhost:3000',
user_name: ENV['SENDGRID_USERNAME'],
password: ENV['SENDGRID_PASSWORD'],
authentication: :plain,
enable_starttls_auto: true }
當我去發送電子郵件在控制檯,它的行爲就像它發送的一樣,但電子郵件從未實際到達:
DeveloperMailer.developer_email(1)#發送電子郵件。似乎工作:
2.3.1 :001 > DeveloperMailer.developer_email(1)
Rendered developer_mailer/developer_email.html.erb (1.5ms)
DeveloperMailer#developer_email: processed outbound mail in 133.3ms
=> #<Mail::Message:70263824429080, Multipart: false, Headers: <From: [email protected]>, <To: ["[email protected]"]>, <Subject: Does SendGrid Work?>, <Mime-Version: 1.0>, <Content-Type: text/html>>
#But I never get anything sent to my email
任何想法我可能會失蹤?
編輯
更新development.rb文件:
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.sendgrid.net',
domain: 'theoremreach.com',
user_name: ENV['SENDGRID_USERNAME'],
password: ENV['SENDGRID_PASSWORD'],
authentication: :plain,
enable_starttls_auto: true }
仍然沒有電子郵件雖然。
我發佈了更新的代碼。儘管沒有電子郵件:( –
你在https://app.sendgrid.com/email_activity的SendGrid活動中看到什麼嗎? – bwest
什麼也沒有。 –