I have been trying to set a global email header across all of our projects with the help of a gem of ours. Currently that gem is used to add a BCC email to all of our emails among other things. I added the code for the header to the method that adds the BCC email address.
The BCC address is added correctly throughout all of our projects so I know that this line of code is definitely run on startup.
This is the code of the gem in question.
ActionMailer::Base.default "FOO" => 'BAR'
bcc = message.bcc.to_a
bcc << BCC_ADDRESS
message.bcc bcc
The idea is that this header is present throughout all of our emails.
Now comes the interesting part and the steps I have taken to create the issue that I am having.
bundle the project with that new gem version
start up a rails console
send any random email
be disappointed that the header does not appear in the email. However the BCC address is properly displayed.
run reload!
send the email again
be confused as to why the header suddenly is present
I tried this in rails 3.2.22.5 (ruby 2.2.4) and rails 4.2.9. (ruby 2.4.1)
The header is not included when running specs however the BCC address is present there.
Does anyone have any idea what might be causing these weird symptoms?
Alright so the issue has to do with defaults being cashed for an email.
So the defaults are not rechecked when you resend the email.
To work around this I changed the way the gem handles to act in between each mail that I want to send by doing the following.
intercept the call for deliver_message
mail.header[:'FOO'] = 'BAR'
Related
So I know I can install the mailer gem from here:
https://guides.spreecommerce.com/user/configuring_mail_methods.html
But it clearly says that generic action mailer settings are more favourable at the top of the page.
I have installed postmark which is sending emails fine in an extension I built. However Spree does not appear to be sending emails when I create an order for a customer. How can I turn these transactional emails on without the Spree mailer gem, as I want to use postmark on its own.
Also where the hell is the listed email section from the documentation?
https://guides.spreecommerce.com/developer/deployment_tips.html
Thanks for any help!
You can set up emails by adding the gem at https://github.com/spree-contrib/spree_mail_settings
Not sure if the message at the top of the page has been changed since this question was posted but it says to use that gem now.
Add gem 'spree_mail_settings', github: 'spree-contrib/spree_mail_settings' to you gemfile and you will get a new page in the admin settings for setting up your email
An update for those facing this issue in 2021:
It's not recommended to use this gem. Instead, use a standard rails configuration: https://guides.rubyonrails.org/action_mailer_basics.html#action-mailer-configuration
This guide on how to fix extensions for Spree 4+ may also come in handy: https://guides.spreecommerce.org/developer/contributing/upgrading_extensions.html
If anyone is desperately in need of this extension, feel free to submit a pull request!
I have been unable to get Spree to send a copy of an order confirmation email after an order is placed. The customer gets the order confirmation however. I can intercept the order confirmation email as well. I have added my email in the Spree Admin "Send Copy of all mails to", as well as having tried adding config.mail_bcc = "contact#mydomain.com" in the config/initializers/spree.rb. I checked the params when I update the Admin, and it does correctly send the mail_bcc = 'contact#mydomain.com'. Any thoughts?
Spree 2.0 has some e-mail settings in the admin area which are a bit problematic. I generally recommend setting:
# config/initializers/spree.rb
Spree.config do |config|
config.override_actionmailer_config = false
end
This will allow you to use the default ActionMailer configuration. Without this setting, Spree will use its own code to handle mail configuration through the admin area.
For more information see:
Spree Deployment Tips
Example ActionMailer Configuration
I previously had a test mailer working (based on the RailsGuides tutorial). When I integrate PostageApp gem and inherit from PostageApp, I get this:
#message="Message layout Provided Message Template is not found., Content can't be blank"
Seems that you're not sending any content over. You are also specifying a postageapp_template that doesn't exists in your PostageApp project for some reason.
Try figuring out what exactly is being sent. In your test (you have tests, right?) have something like this:
email = ActionMailer::Base.deliveries.last
raise email.arguments_to_send.to_yaml
You'll see the actual payload. That should give you a pretty good idea what's missing.
Using Rails 3 I want to use an X.509 certificate to sign parts of emails. There is a currently existing answer for Rails 2 at How do I send signed emails from ActionMailer? but it doesn't work on Rails 3.
Is it possible to sign emails via ActionMailer in Rails 3?
If that is not possible, is it possible to sign emails via sendmail after creating by ActionMailer?
perhaps it's not the best answer, however here's what I'd do:
try to install that plugin (even if it's for rails 2.0.x)
tests and fix code until I get the result
looking at the code, turns out that the core file is:
https://github.com/penso/actionmailer_x509/blob/master/lib/actionmailer_x509.rb
which exposes a bunch of methods for mailer DSL:
x509_sign true # or false
x509_cert "path/to/cert"
x509_key "path/to/key"
x509_passphrase "passphrase"
so you could grab that file, and put it under $APP/lib, then write some test to check it's working.
A.
I have been ported actionmailer_x509 to Rails 3 and wrap it into the gem. So now it works and available here: https://github.com/petRUShka/actionmailer_x509
I have a pretty simple Rails app and I want send an e-mail when a work request is created. I'm pretty new to Rails so I found some details on how to do it online. Set up a Mailer, configured it, etc. Set up my templates. Fine.
In my work_requests_controller.rb I have:
def create
#work_request = WorkRequest.new(params[:work_request])
respond_to do |format|
if #work_request.save
# Tell the mailer to send a welcome Email after save
PersonMailer.work_request_init_email(#work_request).deliver
format.html... etc.
In know mailing is working because if I go to the Rails console, create WorkRequest object, and use that exact same line (PersonMailer.work...) it sends the mail just fine. But when I create a work request in my application no mail is received, no error is displayed in the browser or in logs/development.log.
In the server output I see the HTML version was rendered, and I see the info about the e-mail and it all looks both hunky and dory. Since I get no errors I'm at a loss as to how to proceed.
OK, I am officially an idiot. :-)
Working on a different problem, I was editing application.rb. I figured I needed to restart the server to make it see those changes. Suddenly, the e-mails work from inside the app.
D'oh! I did not realize (rookie mistake) that I needed to restart the server for the app to see the e-mail configuration I had placed in environment.rb yesterday. I never tried that for some reason.
I see now that and other components are run only when the server starts up. So of course, when I started up console of course it runs all the initializers and so the e-mail configuration was visible to it and the e-mails were sent.
So the answer is, restart your server, stupid. Well, anyway, at least it's working now...I'll take it where I can get it!
I would start with moving your email command to your WorkRequest model as a 'after_create' action
after_create :send_init_email
def send_init_email
PersonMailer.deliver_work_request_init_email(self)
end
See if that works, or aleast gives you a better error msg.