I've built a very basic CRM system for my rails app that allows me to send weekly user activity digests with custom text and create multi-part marketing messages which I can configure and send through a basic admin interface. I'm happy with what I've put together on the send-side of things (minus the fact that I haven't tried to volume test its capabilities), but I'm concerned about how to handle bounce-backs.
I came across this plugin with associated scripts: http://github.com/kovyrin/bounces-handler
I'm using Google Apps to handle my mail and really don't know enough about Perl to want to mess with the above plugin - I have enough headaches.
I'm looking for a simple solution for processing bounce-backs in Rails. All my email will go out from an address like this which will be managed in Google Apps: "news#mydomain.com."
What's the best workflow for this? Can anyone post an example solution they're using keeping in mind the fact that I'm using Google Apps for the mail?
Any guidance, links, or basic workflow best-practices to handle this would be greatly appreciated.
Thanks!
-A
Ok, this has proven to be easier then I thought using the Fetcher plugin which you can find on Github. For those interested in an approach that appears to work, here's what I've done:
1) Install the Fetcher plugin like so: script/plugin install git://github.com/look/fetcher.git
2) The instructions suggest you run a generator to create a daemon like so: script/generate fetcher_daemon MailerDaemon. I suggest doing this since it will generate a YML file in config/ which you can modify with your mail server info (in my case Gmail).
It also generates a daemon to run Fetcher. I tried using this but consistently got the following error: Mysql::Error: MySQL server has gone away: SHOW FIELDS FROM email_blacklists. This was the result of the daemon process disappearing before the MySQL could store the record so I abandoned using the daemon and setup a cron instead.
3) configure the .yml file in config which i renamed to mail.yml with your mail settings. For gmail pop, they look something lik this:
development:
type: pop
server: pop.gmail.com
port: 995
ssl: true
username: myemailaddress#gmail.com
password: mypassword
Here's the code you'll need to process:
models/mail_processor.rb
class MailProcessor < ActionMailer::Base
def receive(email)
email = EmailBlacklist.find_or_create_by_email(email.to.first)
end
def self.grab_bounces
config = YAML.load_file("#{RAILS_ROOT}/config/mail.yml")
config = config[RAILS_ENV].to_options
fetcher = Fetcher.create({:receiver => MailProcessor}.merge(config))
fetcher.fetch
end
end
lib/tasks/mail.rake
namespace :email do
desc "sends various types of marketing and automated emails and processes bouncebacks"
task(:process_bounces => :environment) do
MailProcessor.grab_bounces
end
end
You can then toss the auto-generated mailer_daemon_fetcher.rb file in your scripts/ directory.
Hope this helps someone else. If you want to test then, from the console simply call MailProcessor.grab_bounces. Make sure you have some email in the inbox that you're configured to access.
Related
I am creating rails API app for managing Trello related boards and lists.
I have decided to use "ruby-trello" gem.
There is a config example at github ruby-trello page (https://github.com/jeremytregunna/ruby-trello).
Config looks like this:
Trello.configure do |config|
config.developer_public_key = 'my_trello_key'
config.member_token = 'my_trello_token'
end
I got key and token from trello devs.
I have added this code to my config/application.rb in class Application.
But when I am trying to get something data from Trello I see this error:
Trello::ConfigurationError (Trello has not been configured to make authorized requests.)
Can anybody help? Where I need to place this config code?
Sorry for my English.
The Rails convention is to put that in config/initializers/trello.rb so that it's picked up when Rails boots.
It's odd they don't seem to mention that in the documentation.
I recently started following Hartl's Ruby on Rails tutorial.
I downloaded the existing sample_app_reference app from bitbucket.
My goal is not to start and learn everything from scratch but rather to add new features to the already existing app.
The issue is that I can't test the features I'm adding since I can't activate my account locally. In order to activate my account, I need to receive an activation email (which I'm not). I've searched the web for hours, but couldn't find anything regarding the issue. Did anyone try this tutorial before and encountered the same problem? Any help would be much appreciated.
Yeah...sending emails from dev environment is often not straightforward. As Vasilisa comments above, the quickest fix for your need is to activate the user from the rails console...perhaps like this:
% bundle exec rails console
my-app(development)> User.last.activate
However, there will be other times when you actually want to see the email in the context of a mail client. For this, https://mailcatcher.me/ makes it super easy. Just install the mailcatcher gem -- not in your app's Gemfile, but on your local machine's ruby installation.
Then, change the host and port in app/config/development.rb (NOT in other environemnts, like prod!)
config.action_mailer.smtp_settings = {
# For use with Mailcatcher: https://mailcatcher.me/
address: '127.0.0.1',
port: 1025
}
Run mailcatcher once from a command prompt.
Then, do your thing in your app to trigger an email send, and open http://127.0.0.1:1080/ in your browser. Voila, you see your email like it was really sent.
This a super-easy, super-useful way to see real emails without setting up your local env to actually send emails.
I read the solution at: Best way to create custom config options for my Rails app? which seems promising. i.e. storing development and production credentials in config/config.yml. But then I thought.
If we have a team of developers, and interns, they would be exposed to this file with all production credentials. The consensus, is to trust your team. But honest human mistakes do happen: computer left on / unlocked, trojans, friends using the computer, etc.
I know Heroku has something called config vars + foreman. However, for things like AWS, its not as simple as creating a new access key and delegating that access key to a specific bucket. It doesn't work like that. The only way I can think of is to create a new AWS account solely for development purposes. If I go this route, I would have to create development accounts for other similar 3rd party services too.
Is there an alternative option?
I use SettingsLogic.
I create two models for that : Settings and PrivateSettings. And I separate the settings : passwords, token, api key... in PrivateSettings and the rest in Settings.
For Settings :
class Settings < Settingslogic
source "#{Rails.root}/config/settings.yml"
namespace Rails.env
end
The settings.yml file is stored in Git.
For PrivateSettings :
class PrivateSettings < Settingslogic
source "#{Rails.root}/config/private_settings.yml"
namespace Rails.env
end
I store a private_settings-sample.yml file in Git, to keep an example in sync. The production data are obvioulsy not populated. A dev clone the repo, and rename it to private_settings.yml to be able to work.
config/private_settings.yml is also in .gitignore to avoid an inclusion by mistake.
Going to prod, I use a specific task in Capistrano to create a symbolic link to the proper private_settings.yml file stored in the server (in a dir config next to current, releases and shared) :
namespace :deploy do
task :config_settings do
run "cd #{current_path}/config && ln -sf #{shared_path}/../config/private_settings.yml private_settings.yml"
end
end
after "deploy:update", "deploy:config_settings"
i'm not sure if you can prevent developers from knowing the password. even if you have completely separated service that provides you the correct credentials/keys, developers can always debug the working application, add code that logs passwords etc. those are people you have to trust. the only way i see it possible is to have admins that puts required keys on the classpath and always do code reviews to prevent all attempts of reading the credentials at runtime
I need to send a number of emails out from my RoR application, and would like some advice on how best to do this.
Previous questions (e.g. RoR - where to put a automated process) place all the code in the model. However - Because I'm sending out an email, I'm going to have to access an email View. It would seem that the model is not the best place for this.
Should I be putting this process in a controller? If so, what's the best way to initiate it from a cronjob?
In Rails 3, you'd set up an ActiveMailer class in app/mailers/, put the view templates in app/views/ and you could then send emails correctly once your environment is set up.
To access your mailer and actually do the sending, you could set up a Rake task in lib/tasks/cron.rake that requires the environment, like so:
namespace :cron
desc "Sends some emails"
task :send_emails => [:environment] do
MailerName.some_email(:some_option => 'w00t').deliver
end
end
You could then hit this rake task by running a bash shell script somthing like so:
#!/bin/bash
export GEM_HOME=/usr/local/lib/ruby/gems/1.9.1/gems
export GEM_PATH=/usr/local/lib/ruby/gems/1.9.1
cd "/users/yourname/railsapp"
/usr/local/bin/rake cron:send_emails RAILS_ENV=production
Note that this is going to load your entire environment on every run. If you're doing lots of emails, you may find it works better to use curl to periodically hit a specific url on your server, so that you use the existing server Rails instances instead of spinning up a new one on every run.
If you are using rails 3.x, you can place them in app/mailers. Otherwise you can use the lib folder for this purpose.
If the functionality is huge you can split them into separate files and use the following directory structure:
lib/notifier/a.rb
lib/notifier/b.rb
and so on
we're running ARMailer in one of our projects right now.
It's working fine but as different customers are allowed to send confirmation emails via this service we want to offer them the possibility to use their own SMTP settings for that.
Is there a way to change ARMailer settings on the fly?
Or is there an ARMailer alternative maybe which abstracts this better?
Thanks
Matt
this: Using multiple SMTP accounts with Rails & ActionMailer
has a nice example using yaml for storing the multiple configurations, but can easily be adapted to use the db
What I did in the end was:
I took the ARMailer gem and took a copy of it.
After that, modified the email delivery action and started the daemon from my new custom folder. Works fine. Will create a custom some day...