Skip to content

Instantly share code, notes, and snippets.

@woodie
Created February 23, 2010 18:31
Show Gist options
  • Save woodie/312532 to your computer and use it in GitHub Desktop.
Save woodie/312532 to your computer and use it in GitHub Desktop.
ActionMailer JavaMail on AppEngine
require 'appengine-apis/users'
class SomeController < ApplicationController
def welcome
user = AppEngine::Users.current_user
env = AppEngine::ApiProxy.current_environment
UserMailer.deliver_welcome_email(user, env)
render :text => "email sent to: #{user.email}"
end
end
class UserMailer < ActionMailer::Base
def welcome_email(user, env)
body_hash = {:user => user, :app => env}
recipients user.email
from user.email
subject "Welcome to My Awesome Site"
sent_on Time.now
body body_hash
end
end
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
</head>
<body>
<h1>Welcome <%=h @user.nickname %></h1>
<p>
Thanks for visiting: <b><%=h @app.getAppId %></b><br/>
Your auth_domain is: <b><%=h @user.auth_domain %></b><br/>
</p>
<p>Have a great day!</p>
</body>
</html>
# ...
if defined? JRUBY_VERSION
require "rails_appengine/action_mailer_vendored"
require "rails_appengine/active_support_vendored"
require "rails_appengine/bundler_boot"
end
# All that for this:
Rails.boot!
# Be sure to restart your server when you modify this file
# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION
# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')
Rails::Initializer.run do |config|
# Skip these so generators can run from MRI
if defined? JRUBY_VERSION
# Use vendored version of tmail
require 'rails_appengine/action_mailer_vendored'
# Use DataMapper to access datastore
require 'rails_dm_datastore'
# Set Logger from appengine-apis, all environments
require 'appengine-apis/logger'
config.logger = AppEngine::Logger.new
# Skip frameworks you're not going to use.
config.frameworks -= [ :active_record, :active_resource ] #, :action_mailer ]
end
# Skip plugin locators
config.plugin_locators -= [Rails::Plugin::GemLocator]
config.time_zone = 'UTC'
end
if defined? JRUBY_VERSION
require 'java_mail'
ActionMailer::Base.delivery_method = :javamail
ActionMailer::Base.javamail_settings = { :protocol => :gm }
end
# Critical default settings:
disable_system_gems
disable_rubygems
bundle_path '.gems/bundler_gems'
# List gems to bundle here:
gem 'jruby-openssl', '0.5.2'
gem 'rails', "2.3.5"
gem 'rails_dm_datastore', "0.2.5"
gem "actionmailer-javamail", :require_as => "java_mail"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment