我正在尝试使用smtp方法发送邮件,我在 development.rb 文件中进行了配置,这里是
Rails.application.configure do
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'example.com',
user_name: 'angad1@gmail.com',
password: xxxxxxxx,
authentication: 'plain',
enable_starttls_auto: true
}
这是在mailers文件夹下的UserMailer,这里我从控制器获取参数值,并将参数分配给varible,以便它可供视图使用 的 UserMailer.rb
class UserMailer < ApplicationMailer
default from: 'angad1@gmail.com'
layout 'mailer'
def conference_result(email,proposal,acknowledgement,positive,negative,chart)
@email = email
@proposal = proposal
@acknowledgement = acknowledgement
@positive = positive
@negative = negative
@chart = chart
mail(to: @email , subject: 'Result for Your conference meeting' , content_type: "text/html")
end
end
以下是我想通过邮件发送的内容, 的 mailer.html.erb
<body>
<%= yield %>
<h3 class="text-center" id="proposalhead">Proposal</h3>
<div style="border:1px solid rgba(0,0,0,0.3);background-color: rgba(255,255,255,0.1);margin-top:10px;margin-bottom:10px;" class="text-center">
<%= @proposal %>
</div>
<h3 class="text-center hidden" id ="acknowledgementhead">Acknowledgement</h3>
<div style="border:1px solid rgba(0,0,0,0.3);background-color: rgba(255,255,255,0.1);margin-top:20px;margin-bottom:20px;" id ="Acknowledgement" class="text-center">
<%= @acknowledgement %>
</div>
<h3 class="text-center hidden" id ="positivehead">Positive</h3>
<div style="border:1px solid rgba(0,0,0,0.3);background-color: rgba(255,255,255,0.1);margin-top:10px;margin-bottom:10px;" id ="Positive" class="text-center">
<%= @positive %>
</div>
<h3 class="text-center hidden" id ="negativehead">Negative</h3>
<div style="border:1px solid rgba(0,0,0,0.3);background-color: rgba(255,255,255,0.1);margin-top:10px;margin-bottom:20px" id = "Negative" class="text-center">
<%= @negative %>
</div>
<div id="chart_div" style="width:100%;margin-bottom: 15px;margin-top:15px;" class="text-center">
<%= @chart %>
</div>
</body>
当我尝试发送邮件时,它显示以下错误
ActionView :: MissingTemplate(缺少模板user_mailer / conference_result with“mailer”。搜索:*“user_mailer”)
请帮帮我,我是红宝石的新手。
答案 0 :(得分:3)
如错误所示,缺少模板user_mailer / conference_result 。
您需要创建模板javax.ws.rs.ProcessingException: Error reading entity from input stream.
答案 1 :(得分:0)
您似乎错过了邮件模板本身。如果你还没有得到它,那就解释了错误 - 否则我确保它在正确的文件夹中,可能是app/views/user_mailer/conference_result.html.erb
和.text.erb
。
答案 2 :(得分:0)
https://myaccount.google.com/u/0/lesssecureapps
登录您的电子邮件,然后打开上面的链接。 启用lesssecure app。