2

我正在使用 rails3.0.6 和 ruby​​ 1.8.7,我可以轻松地从我的应用程序开发模式发送电子邮件。但是昨晚我尝试向我的客户电子邮件发送邮件时看到一个新错误,该邮件与我的发票模型相关联。错误是:

Net::SMTPSyntaxError in InvoicesController#email_invoice 
501 < @invoice.account.accountable.email >: missing or malformed local part

我的 email.rb 文件代码是:

 def send_invoice(invoice)
   email = '@invoice.account.accountable.email'
   mail(:to => email, :from => "support@thenextwave.in", :subject=>"Invoice, check it.") 
 end

在我的invoice controller我做了:

def email_invoice
  @company = Company.find(User.find(session[:current_user_id]))
  @invoice = Invoice.find(params[:id])
  @invoice_line_items = @invoice.invoice_line_items
  @receipt_vouchers = @invoice.receipt_vouchers
  #email = @invoice.account.accountable.email
  Email.send_invoice(@invoice).deliver
  redirect_to invoice_path(@invoice)
  flash[:success] = 'Email has been sent successfully.'
end

我仔细检查了这个错误,发现它是由于电子邮件地址错误或 SMTP 设置错误引起的,但我的 SMTP 设置没问题,因为我可以从我的应用程序发送电子邮件,但下面一行有问题:

@invoice.account.accountable.email

任何帮助都会非常感谢..

4

1 回答 1

1

我想出了一个解决方案,我email.rb在邮件中的文件中犯了错误:

def send_invoice(invoice)
  email = '@invoice.account.accountable.email'
  mail(:to => email, :from => "support@thenextwave.in", :subject=>"Invoice, check it.") 
end

它应该是:

def send_invoice(invoice)
  email = invoice.account.accountable.email 
  mail(:to => email, :from => "support@thenextwave.in", :subject=>"Invoice, check it.") 
end

现在我可以轻松发送电子邮件了..

于 2012-04-17T06:54:42.633 回答