1

我在死胡同!我正在尝试制作一个应用程序来接收 hotmail 上的电子邮件!我创建了一个方法,但我收到一个错误并且没有收到电子邮件..

在我的方法中:

class Recivemail < ActiveRecord::Base
  attr_accessible :content, :from, :subject

 def sendmail(content,from,subject)
    subject = 'subject'
    recipients = "linkinpark_8884@hotmail.com"
    from = 'from'
    sent_on = Time.now
  end 
end

在配置>环境>development.rb

config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings ={
    :enable_starttls_auto => true,
    :address => 'smtp.hotmail.com',
    :port => 587,
    :authentication => :plain,
    :domain => 'localhost:3000',
    :user_name => 'linkinpark_8884@hotmail.com',
    :password => 'mypass'

  }

在视图>接收邮件>显示

<%=@recivemail.sendmail(@recivemail.from,@recivemail.subject,@recivemail.content)%>

一切似乎都正常,除了我没有收到任何电子邮件任何想法?同样在路径 C:/Sites/recivemail 路径上的 cmd(我在 Windows 中)我已经运行 gem install activemailer

4

2 回答 2

1

我在您的 sendmail 方法中看不到任何实际发送邮件的内容。您所做的只是设置 4 个实例变量。我不认为你真的试图发送邮件。我也看不到您在方法中将内容参数设置为变量的位置。

我也认为你的邮件对象应该来自 ActionMailer::Base

class ReceiveMail < ActionMailer::Base
  default :return_path => 'system@example.com'

  def sendmail(content,from,subject)
     mail(:to => "linkinpark_8884@hotmail.com",
         :bcc => ["bcc@example.com", "Order Watcher <watcher@example.com>"],
             :subject => subject,
             :content => content) # use whatever mail headers are appropriate
  end

end

然后在您的控制器中,而不是您的模型中,调用.deliver您在控制器操作而不是活动记录模型中创建的 ActionMailer::Base 对象模型。

控制器可能看起来像这样

class MailController < ApplicationController
def mails
  ReceiveMail.sendmails(params[])
   @message = ReceiveMail(params[content], params[subject], params[from]) #pass params if form POST
   @message.deliver
end

end

您可能还必须定义这个:

ActionMailer::Base.template_root = "mailer/templates"
  # mailer will look for rhtml templates in that path
  # example: "mailer/templates/my_mailer/signup_mail.rhtml"

在 config/environments/development.rb/production.rb

于 2012-06-25T18:58:16.790 回答
0

http://www.coupa.org/2006/12/12/receiving-emails-with-actionmailer-on-windows/

于 2012-06-26T07:17:32.967 回答