我正在使用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
任何帮助都会令人痛苦..
答案 0 :(得分: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
现在我可以轻松发送电子邮件..