Sendgrid /无法收到电子邮件 [英] Sendgrid/can't get emails
问题描述
现在我正在尝试建立一个联系表单并删除所有的错误。但是我收不到电子邮件。您能给我一些建议吗?
☆ Heroku日志
2013-12-18T06:20:34.807594 + 00:00 app [web.1]:Started POST/联系人为118.237.94.47于2013-12-18 06:20:34 +0000
2013-12-18T06:20:34.813037 + 00:00 app [web.1]:通过ContactsController处理#以HTML格式创建
2013-12-18T06:20:34.813037 + 00:00 app [web.1]:参数:{utf8=>✓,authenticity_token=>2e9zz3cX0tZwYTZhaPbRRYQufff31fZk4OjjF7sdeo =,contact => {name=>じゃじゃじゃ,email=>jaja@gmail.com,content=>じゃじゃじゃ},commit=> 创建联系人}
2013-12-18T06:20:34.843217 + 00:00 app [web.1]:呈现的contact_mailer / sent.text.erb(0.5ms)
2013-12-18T06 :20:35.265031 + 00:00 heroku [router]:at = info method = POST path = / contacts host = www.tsundoku-buster.jp fwd =118.237.94.47dyno = web.1 connect = 4ms service = 464ms状态= 302字节= 116
2013-12-18T06:20:35.259745 + 00:00 app [web.1]:
2013-12-18T06:20:35.259745 + 00:00 app [web.1]:发送邮件到myemail @ gmail .com(412ms)
2013-12-18T06:20:35.260551 + 00:00 app [web.1]:重定向至http://www.tsundoku-buster.jp/static_pages/contact
2013-12-18T06:20:35.260715 + 00:00 app [web.1]:完成302发现于448ms(ActiveRecord:11.4ms)
到目前为止,我做了如下工作。
①app/ mailers / contact_mailer.rb
class ContactMailer< ActionMailer :: Base
默认来自:myemail@gmail.com
#可以在config / locales / en.yml的I18n文件中设置主题
#以下查询:
#
#en.contact_mailer.sent.subject
#
def sent(contact)
@contact = contact
mail:(:to =>myemail@gmail.com,:subject =>'TsundokuBuster発お问い合わせ')
end
end
②app/ views / contact_mailer / sent.text.erb
以下の内容でお问い合わせ顶きました。
お名前
<%= @ contact.name%>
メールアドレス
<%= @ contact.email%>
我的合约内容
<%= @ contact.content%>
<3>③contact.rb
class Contact< ActiveRecord :: Base
attr_accessible:name,:email,:content
validates:name,:email,:content,:presence => true
end
cf. http://sendgrid.com/docs/Integrate/Frameworks/rubyonrails.html
④contacts_controller.rb
#encoding:utf-8
类ContactsController< ApplicationController
def创建
@contact = Contact.new(params [:contact])
如果@ contact.save
ContactMailer.sent(@contact).deliver
redirect_to static_pages_contact_path,:notice => '
else
render static_pages_contact_path,:alert =>'
else
render static_pages_contact_path,:alert => '
end
end
end
⑤在heroku仪表板上添加Sendgrid插件
$ b
⑥搜索我的SENDGRID_USERNAME和SENDGRID_PASSWORD
cf. < https://devcenter.heroku.com/articles/sendgrid
b $ b
⑦编辑config / environment.rb
ActionMailer :: Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => ENV ['myappusername@heroku.com'],
:password => ENV ['mypassword'],
:domain => 'www.mydomain.jp',
:enable_starttls_auto => true
ActionMailer :: Base.delivery_method =:smtp
⑧gitadd 。 git commit git push heroku master
适合所有初学者。
只需在您的命令中执行heroku config即可。
然后你会得到这样的东西。
SENDGRID_PASSWORD:xxxxxxxxx
SENDGRID_USERNAME:xxxxxxx@heroku.com
这是哈希。所以如果你想隐藏你的密码以及用户名,你应该写下如下代码:
:password => ENV ['SENDGRID_PASSWORD']
:user_name => ENV ['SENDGRID_USERNAME']
如果你不介意显示你的密码,你可以写下如下:
:password => xxxxxxxxx
:user_name => xxxxxxx@heroku.com
Now I am trying to set up a contact form and removed all the errors.But I can't get email.Could you give me some advice?
☆heroku logs
2013-12-18T06:20:34.807594+00:00 app[web.1]: Started POST "/contacts" for 118.237.94.47 at 2013-12-18 06:20:34 +0000
2013-12-18T06:20:34.813037+00:00 app[web.1]: Processing by ContactsController#create as HTML
2013-12-18T06:20:34.813037+00:00 app[web.1]: Parameters: {"utf8"=>"✓", "authenticity_token"=>"2e9zz3cX0tZwYTZhaPbRRYQufff31fZk4OjjF7sdeo=", "contact"=>{"name"=>"じゃじゃじゃ", "email"=>"jaja@gmail.com", "content"=>"じゃじゃじゃ"}, "commit"=>"Create Contact"}
2013-12-18T06:20:34.843217+00:00 app[web.1]: Rendered contact_mailer/sent.text.erb (0.5ms)
2013-12-18T06:20:35.265031+00:00 heroku[router]: at=info method=POST path=/contacts host=www.tsundoku-buster.jp fwd="118.237.94.47" dyno=web.1 connect=4ms service=464ms status=302 bytes=116
2013-12-18T06:20:35.259745+00:00 app[web.1]:
2013-12-18T06:20:35.259745+00:00 app[web.1]: Sent mail to myemail@gmail.com (412ms)
2013-12-18T06:20:35.260551+00:00 app[web.1]: Redirected to http://www.tsundoku-buster.jp/static_pages/contact
2013-12-18T06:20:35.260715+00:00 app[web.1]: Completed 302 Found in 448ms (ActiveRecord: 11.4ms)
What I have done so far is as follows.
①app/mailers/contact_mailer.rb
class ContactMailer < ActionMailer::Base
default from: "myemail@gmail.com"
# Subject can be set in your I18n file at config/locales/en.yml
# with the following lookup:
#
# en.contact_mailer.sent.subject
#
def sent(contact)
@contact = contact
mail(:to => "myemail@gmail.com", :subject => 'TsundokuBuster発お問い合わせ')
end
end
②app/views/contact_mailer/sent.text.erb
以下の内容でお問い合わせ頂きました。
お名前
<%= @contact.name %>
メールアドレス
<%= @contact.email %>
お問い合わせ内容
<%= @contact.content %>
③contact.rb
class Contact < ActiveRecord::Base
attr_accessible :name, :email, :content
validates :name, :email, :content , :presence => true
end
cf.http://sendgrid.com/docs/Integrate/Frameworks/rubyonrails.html
④contacts_controller.rb
#encoding: utf-8
class ContactsController < ApplicationController
def create
@contact = Contact.new(params[:contact])
if @contact.save
ContactMailer.sent(@contact).deliver
redirect_to static_pages_contact_path, :notice => 'お問い合わせありがとうございました。'
else
render static_pages_contact_path, :alert => 'お問い合わせに不備があります。'
end
end
end
⑤Adding Sendgrid add-on at heroku dashboard
⑥Search for my SENDGRID_USERNAME and SENDGRID_PASSWORD
cf.https://devcenter.heroku.com/articles/sendgrid
⑦Editing config/environment.rb
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => ENV['myappusername@heroku.com'],
:password => ENV['mypassword'],
:domain => 'www.mydomain.jp',
:enable_starttls_auto => true
}
ActionMailer::Base.delivery_method = :smtp
⑧git add. git commit git push heroku master
For all beginners.
Just do "heroku config" on your command. Then you will get something like this.
SENDGRID_PASSWORD: xxxxxxxxx
SENDGRID_USERNAME: xxxxxxx@heroku.com
This is hash. So if you want to hide your password as well as username, you should write the code like
:password => ENV['SENDGRID_PASSWORD']
:user_name => ENV['SENDGRID_USERNAME']
If you don't mind to show your password, you can write this as follows;
:password => xxxxxxxxx
:user_name => xxxxxxx@heroku.com
这篇关于Sendgrid /无法收到电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!