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
Related
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'
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 need to get the username of the currently logged windows user. Could it be done easily?
The username of the account running the script can be accessed via something like:
puts ENV['USERNAME']
Beware that if you're running it as a system service the username will probably come back as "SYSTEM"
If that isn't enough to suite your needs there is an alternative method outlined here: https://stackoverflow.com/a/3544741/648695
You can use the Ruby etc module
require 'etc'
Etc.getlogin
The doc is avaiable here: http://ruby-doc.org/stdlib-2.0.0/libdoc/etc/rdoc/Etc.html#method-c-getlogin
Returns the short user name of the currently logged in user.
As far as I know, unless you're using active directory that would require a microsoft framework website, I don't think you'll find a way in rails.
There are a few discussion points here that may help: Can you get a Windows (AD) username in PHP?
Same question here: is there a way to read a clients windows login name using ruby on rails
Anyways, just copying my own answer below...
This is what worked for me but there are some limitations:
won't work in Chrome: undefined method 'encode' for nil:NilClass
won't validate user credentials
If you don't care about these issues, go ahead:
In your rails application, add Rekado's gem to your Gemfile: gem 'ntlm-sso', '=0.0.1'
Create an initialiser config/initializers/ntlm-sso.rb with:
require 'rack'
require 'rack/auth/ntlm-sso'
class NTLMAuthentication
def initialize(app)
#app = app
end
def call(env)
auth = Rack::Auth::NTLMSSO.new(#app)
return auth.call(env)
end
end
On your application.rb file, add the line: config.middleware.use "NTLMAuthentication"
Call request.env["REMOTE_USER"] on your view or controller to get current username.
PS: Let me know if you find anyway to make it work on Chrome or to validate user credentials.
I'm using Devise for authentication, and I'm confused on how to set up mail along with it. Should you still be creating your own mailer and initializer file, or should you be sending all mail through Devise? Where do you go in Devise to create the email template and the method for sending the email?
I realize this is kind of a broad question, so essentially I'm asking what is the best way to set up mail with Devise?
Also, if you wanted to send an email to a user after they have confirmed their email, how would you do this?
Devise does create it's own Mailer--if you take a look on GitHub https://github.com/plataformatec/devise/blob/master/app/mailers/devise/mailer.rb you can see that it comes with a bunch of methods already packaged in.
You can go ahead and generate the views for these methods using the command
rails g devise views
and then edit them.
If you would like to send additional email messages you should create your own Mailer to do so. I would recommend http://edgeguides.rubyonrails.org/action_mailer_basics.html . It's a pretty good overview of how to set up a mailer from the ground up.
Devise creates the mailer and email templates for you, so you don't have to worry about that. However, if you want to change the email templates, install devise views using the command:
rails g devise:views
This will add a new "devise" folder in your views. You can find all the email templates in the mailer folder under views/devise.
Use the confirmable attribute to send confirmation emails to users post registration.
By default, this attribute is commented out. So, once you install devise using the command rails g devise:install, go to db/migrate and locate the devise_create_users migration and uncomment the following lines:
t.confirmable and
add_index :users, :confirmation_token, :unique => true.
Once done, migrate your database.
Now go to your user model and check if devise has the :confirmable attribute, if not add it and you are all set.
I'm using rails 2.3.5 and devise 1.0.6.
I'm having users confirm account's with email.
However, when a new user sign's up the flash notice says "The user was successfully created" which it was but it doesn't tell the user that they need to confirm their their email unless they try to log in and devise's flash notice still doesn't explain that they have to confirm through email.
Where is this flash notice located in the gem and how can I change it? Or what is a better way to fix this problem.
Just enable i18n in your project and edit the default locale (en.devise.yml) or download new ones from
https://github.com/plataformatec/devise/wiki/i18n
Flash messages for the devise gem can be altered in the locales directory (YourRailsApp/config/locales/devise.en.yml).
Just change the devise.en.yml to your liking, it doesn't really take any programming knowledge.
If you are new to rails the locales directory is for I18n translations which is rails way of translating words albeit statically but it works well for simple projects.