The error seems to be very non-descriptive:
failed with ArgumentError: A sender (Return-Path, Sender or From) required to send a message
I think this is not the real problem since I've tried specifying "from" even though I set a default. Also, the code is identical for localhost and Heroku...
def invite_dealer(auction, name, email, dealer)
return false if dealer.bids.where("auction_id = ?", auction.id).present?
#name = name #used on template
#email = email
#auction = auction #this too
mail(:to => #email, :subject => "New Auction - #{auction.car.name}", :from => "realaddressishereonmymachine#ourdomain.com")
end
The error failed with ArgumentError: A sender (Return-Path, Sender or From) required to send a message can occur if mail method was not invoked from invite_dealer method.
So putting conditional return into invite_dealer method before call to mail method is bad idea.
Adding this line to development.rb seems to have fixed it - strange all the other mail methods were working:
Rails.application.routes.default_url_options[:host]= 'localhost:3000'
Related
I use Rails 3 + Postmark-Rails.
At first, I created account on postmarkapp.com to get my api key.
I Activated my signature by email link [for example, "vitalyp#dot.com"]
-- After that, I added this to application.rb
config.action_mailer.delivery_method = :postmark
config.action_mailer.postmark_settings = { :api_key => "fdcb..." }
I use this method to send emails:
class UserMailer < ActionMailer::Base
default :from => "vitalyp#dot.com"
def do_my_mail(to, subj)
mail(:to => to, :subject => subj)
end
I get this error:
Postmark::InvalidMessageError
Sender signature not defined for From address.
Any ideas?
SPF and DKIM are recommended, not required. However, sender signature is required (as stated in the documentation).
Are you sure you are using the same From address as the one used to create the sender signature? This can happen if you are using different email.
Postmark uses sender signatures to make sure you don't use their service for spam purposes:
From http://developer.postmarkapp.com:
"Sender signatures are needed in order to verify that, well, you really own the mailbox, and that you are not a spammer (yes, we hate spam too). You must have a sender signature for each from address used in your application."
I am trying to send email with attachments using Ruby on Rails.
I followed the instructions from the ActionMailer site.
def welcome(recipient)
#account = recipient
attachments['file.csv'] = File.read('/path/to/users.csv')
mail(:to => recipient,
:bcc => ["email#example.com", "email2#example.com"],
:subject => "Sending attachment")
end
I am able to receive emails but without the attachment, I am trying to attach csv file but I am getting a file called "noname" as attachment
I just had this problem. I was not providing a body for the email, and was sending the attachment only. Unfortunately, it appears that SendGrid gets confused by this, sending an empty email (which is expected) with an empty attachment (which is neither expected nor desired).
Therefore, the solution: provide a body for the email. In your specific case, an /app/views/application_mailer/welcome.text.erb template with a simple text, saying "See attached" or whatever appropriate.
SendGrid is an SMTP service, and thus should function just as any other outbound SMTP service. Are you sure your syntax and filepaths are correct?
class ApplicationMailer < ActionMailer::Base
def welcome(recipient)
attachments['free_book.pdf'] = File.read('path/to/file.pdf')
mail(:to => recipient, :subject => "New account information")
end
end
Verify correct syntax
Verify correct filepath
Verify permissions on file are set correctly
Check your logs
I'm trying to delay a notification email to be sent to users upon signing up to my app. The emails are sent using an ActionMailer which I call InitMailer. The way I am trying to delay the jobs is using collectiveidea's delayed_job https://github.com/collectiveidea/delayed_job. To do this you can see that i specify handle_asynchronously after defining the method initial_email:
class InitMailer < ActionMailer::Base
default :from => "info#blahblahblah.com"
def initial_email(user)
#user = user
#url = "http://www.blahblahblah.com"
mail(:to => user.email,
:subject => "Welcome to my website!"
)
end
handle_asynchronously :initial_email
end
However, I encounter an argument error in my log file "delayed_job.log":
Class#initial_email failed with ArgumentError: wrong number of arguments (1 for 0) - 5
failed attempts
For your information, the email is sent in a controller using the line:
#user = InitUser.new(params[:init_user])
InitMailer.delay.initial_email(#user)
Additionally, when I set up my code without the delay, the emails were sent out without problem (except for the fact that it slowed down my app waiting for gmail servers)
Where is causing the errors here? How can I get the delayed mail to send properly?
Due to the way that Rails3 implements mailers, there are some unusual workarounds for delayed_jobs. For instance, you have seen that to delay the mailing, you write
ExampleMailer.delay.example(user)
While typically you would have to write handle_asynchronously after the method definition, in the case of mailers this declaration (for some reason) prevents that delayed job from working.
So in this code, drop the declaration entirely:
class InitMailer < ActionMailer::Base
default :from => "info#blahblahblah.com"
def initial_email(user)
#user = user
#url = "http://www.blahblahblah.com"
mail(:to => user.email,
:subject => "Welcome to my website!"
)
end
#No handle_asynchronously needed here
end
I'm wondering how I could conditionally abandon sending mail within the action ActionMailer action itself.
class SomeMailer < ActionMailer::Base
...
def some_emails
some_models = Model.where(:a => 1)
if !some_models.blank?
mail(...)
else
# What to add here?
# render :nothing => true doesn't work
end
end
end
Now invoking this through SomeMailer.some_emails.deliver! returns an
ArgumentError: A sender (Return-Path, Sender or From) required to send a message
Set perform_deliveries to false, like so:
emails = get_email_list_somehow
if emails.present?
mail options.merge(:bcc => emails)
else
self.message.perform_deliveries = false
end
This will quietly not try to send and should stop the error from happening.
In Rails 3.2.9 you can finally conditionally call mail(). Here's the related GitHub thread. Now the OP's code can be reworked like this:
class SomeMailer < ActionMailer::Base
...
def some_emails
some_models = Model.where(:a => 1)
unless some_models.blank?
mail(...)
end
end
end
The strange thing is, that with Rails 3.1.rc4 and WEBrick, it works fine on my local WEBrick webserver. But as soon as I push to Heroku cedar stack, their WEBrick throws the
ArgumentError: A sender (Return-Path, Sender or From)
You have to remove the conditional statements as stated in above answer. That fixes it so that it also works on Heroku, not just your local machine
I had this same problem. There is no real way to do it within the ActionMailer action so I did the following in my cron task:
users.each do |user|
begin
UserMailer.event_second_reminder_group_user_email(user).deliver
puts " - sending reminder email to user #{user.email}"
rescue
end
end
puts "Complete!"
Now if an error is thrown, it doesn't break the app!
Instead put your conditions in the place where you are making the call to SomeMailer.some_emails.deliver!
I'm running 2.1.1, Rails 3, and having a heckuva time getting the delayed_job gem working. If I strip out handle_asynchronously on a mailer, everything works fine...but if I put it back in, I get:
undefined method `name' for nil:NilClass (where 'name' comes from #contact.name ...which works fine when handle_asynchronously is disabled).
If I strip out all the #contact template info, I get:
"A sender (Return-Path, Sender or From) required to send a message"?
Is this me doing something wrong or some sorta bug? Relevant code below (my#email.here replaced with legit email address)
class ContactMailer < ActionMailer::Base
default :from => "my#email.here"
def contact_mail(contact)
#contact = contact
mail(:to => ENV['MANAGER_EMAIL'], :subject => 'Delayed Job Test', :from => 'my#email.here', :content_type => 'text/plain')
end
handle_asynchronously :contact_mail, :run_at => Proc.new { 2.seconds.from_now }
end
Any suggestions very appreciated.
Try calling the method with the actual email address:
def contact_mail(contact_email)
mail(:to => ENV['MANAGER_EMAIL'], :subject => 'Delayed Job Test', :from => contact_email, :content_type => 'text/plain')
end
That's the only thing I can think of which might help without seeing your actual code. Your error says you're calling name on a nil object, but I can't see anywhere where you're calling .name...
I had the same problem and solved it by removing this line:
default :from => "my#email.here"
But I don't know why it crashed with this line..
Rails 3 Mailers
Due to how mailers are implemented in Rails 3, we had to do a little work around to get delayed_job to work.
# without delayed_job
Notifier.signup(#user).deliver
# with delayed_job
Notifier.delay.signup(#user)
Remove the .deliver method to make it work. It’s not ideal, but it’s the best we could do for now
https://github.com/collectiveidea/delayed_job#rails-3-mailers