Tag: ruby on rails 4动作管理器

Rails 4,Mailer预览,预览附加图像

我有rails 4.1.6邮件程序预览的问题。 我想在预览模式下看到附加的图像,但它不起作用。 我认为这是不正确的 有我的代码: 邮件文件 class AppMailer < ActionMailer::Base default from: "robot@mysite.com" # AppMailer.test_mail.deliver def test_mail attachments.inline['rails.png'] = File.read(Rails.root.join('app', 'assets', 'images', 'rails.png')) mail( to: 'my-email@gmail.com', subject: "test letter", template_path: "mailers", template_name: "test" ) end end 预览文件 class MailerPreview < ActionMailer::Preview def app_mailer AppMailer.test_mail end end 模板文件 %p Hello, World! %p= image_tag attachments[‘rails.png’].url 当我去 /rails/mailers/mailer/app_mailer […]

ArgumentError:发送邮件需要SMTP To地址。 设置消息smtp_envelope_to,to,cc或bcc地址

我有一个带有以下邮件配置的rails 4应用程序: config.action_mailer.delivery_method = :smtp config.action_mailer.default_url_options = { host: ‘myhost.com’ } config.action_mailer.perform_deliveries = true config.action_mailer.smtp_settings = { :enable_starttls_auto => true, :address => ‘smtp.myhost.com’, :port => 587, :domain => ‘myhost.com’, :authentication => :login, :enable_starttls_auto => false, :tls => false, :openssl_verify_mode => ‘none’, :ssl => false, :user_name => “myusername”, :password => “mypassword” } 每次我尝试发送带有测试邮件设置的邮件时: class TestMailer “noreply@myhost.com” […]

Rails 4.1强制ActionMailer返回其他值

如何强制在ActionMailer方法中返回另一个值。 例: class TestMailer < ActionMailer::Base extend MandrillApi def index(email, code) @code = code result = MandrillApi.send({subject: t('test.index.subject'), to: email, template: render_to_string}) return result end end 在这种情况下,我使用ActionMailer渲染模板(render_to_string)并将变量传递给视图,但我需要从MandrillApi模块获取结果值。 当我调用方法TestMailer.index(“xxxx@gmail.com”, “asdf123”) ,返回值为# 谢谢!!