使用邮件 gem 和 smtp 传递方法轨道发送邮件



我正在尝试使用 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  
    }

这是邮件文件夹下存在的UserMailer,在这里我从控制器获取参数值,并将参数分配给变量,以便它可以用于视图 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 (Missing template user_mailer/conference_result with "mailer"。搜索位置:* "user_mailer"(

请帮帮我,我是红宝石的新手。

正如错误所说,缺少模板user_mailer/conference_result

您需要创建一个模板app/views/user_mailer/conference_result.html.erb

您似乎缺少邮件模板本身。如果你没有得到它,这就解释了错误 - 否则我会确保它在正确的文件夹中,可能是app/views/user_mailer/conference_result.html.erb.text.erb.

https://myaccount.google.com/u/0/lesssecureapps

登录您的电子邮件,然后打开上面的链接。启用不太安全的应用程序。

最新更新