【问题标题】:Sending mail using mail gem and smtp delivery method rails使用 mail gem 和 smtp 发送方法 rails 发送邮件
【发布时间】:2017-06-14 06:43:52
【问题描述】:

我正在尝试使用我在 development.rb 文件中完成的配置的 smtp 方法发送邮件,这里是

    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,这里我从控制器获取参数值,并将参数分配给变量,以便视图可以使用它 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

这是我想通过邮件传递的内容, ma​​iler.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(缺少带有“mailer”的模板user_mailer/conference_result。搜索到:*“user_mailer”)

请帮帮我,我是 ruby​​ 新手。

【问题讨论】:

  • user_mailer forlder 中是否有 Conference_result 电子邮件模板?

标签: ruby-on-rails ruby


【解决方案1】:

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

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

【讨论】:

  • 感谢您的帮助,gmail 正在发送邮件,但它是邮件,Google 刚刚阻止了某人登录您的 Google 帐户。如何克服这一点。
  • 登录您的帐户后转到此处并启用对安全性较低的应用程序的访问google.com/settings/security/lesssecureapps
  • 谢谢,我已经完成了。我发送的内容没有以正确的格式显示。我在邮件中收到类似的内容 ---==_mimepart_5940e1d369d8f_282d2658644331d6 内容类型:文本/清楚的; charset=UTF-8 Content-Transfer-Encoding: 7bit ----==_mimepart_5940e1d369d8f_282d2658644331d6 Content-Type: text/html; charset=UTF-8 内容传输编码:quoted-printable
  • 安加德:是的,他应该有。抛开这一切,你的项目进展如何?
    Tej:是的
    Tej:是的,我同意 angad。
  • 您在电子邮件中看到的内容完全取决于您创建的视图。您不应该对相同/不相关的帖子提出多个问题。欢迎您提出另一个问题:)
【解决方案2】:

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

【讨论】:

  • 感谢您的帮助。Gmail 正在发送邮件,但邮件中包含,Google 刚刚阻止某人登录您的 Google 帐户。如何克服这个
【解决方案3】:
https://myaccount.google.com/u/0/lesssecureapps

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-28
    • 2018-07-28
    • 2016-09-03
    • 1970-01-01
    • 2016-01-13
    • 2010-12-06
    • 2017-06-26
    • 1970-01-01
    相关资源
    最近更新 更多