i am using rails3.0.6 and ruby 1.8.7, i can easily send email from my applications development mode.But last night i saw a new error when i tried to send mail to my customers email which is polymorphic associated with my invoice model. The error is:
Net::SMTPSyntaxError in InvoicesController#email_invoice
501 < @invoice.account.accountable.email >: missing or malformed local part
My code for email.rb file is :
def send_invoice(invoice)
email = '@invoice.account.accountable.email'
mail(:to => email, :from => "support@thenextwave.in", :subject=>"Invoice, check it.")
end
and in my invoice controller i did:
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
i goggled for this error and find that it causes due to wrong from and to email addresses or wrong SMTP settings, but my SMTP setting is ok since i can send email from my application but has problem with below line:
@invoice.account.accountable.email
any help would be thaknful..
I come up with a solution, I made mistake in
email.rbfile in my mailer :it should be:
Now I can send email easily..