<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: actionmailer code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 11 Oct 2008 16:25:30 GMT</pubDate>
    <description>DZone Snippets: actionmailer code</description>
    <item>
      <title>mail sending program using ssl using gmail account</title>
      <link>http://snippets.dzone.com/posts/show/5486</link>
      <description>// sending mail using ruby through ssl&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'rubygems'&lt;br /&gt;require 'action_mailer'&lt;br /&gt;require "net/smtp"&lt;br /&gt;require "tlsmail"&lt;br /&gt;&lt;br /&gt;class MailSent &lt; ActionMailer::Base&lt;br /&gt;  def message(r = "", m = "", s = "", f = "", c = nil)&lt;br /&gt;    begin&lt;br /&gt;      fail StandardError, "No Recipient" if r.empty? #and b.empty?&lt;br /&gt;      fail StandardError, "No Message" if m.empty? &lt;br /&gt;      fail StandardError, "No Subject" if s.empty?&lt;br /&gt;      fail StandardError, "No From" if s.empty?&lt;br /&gt;      from f&lt;br /&gt;      recipients r&lt;br /&gt;      cc c if c and !c.empty?&lt;br /&gt;      subject s&lt;br /&gt;      body m&lt;br /&gt;    rescue Exception =&gt; e&lt;br /&gt;      puts e&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;class SentMail&lt;br /&gt;  def get_value(to,msg,sub,from,pass=nil,cc=nil)&lt;br /&gt;    begin&lt;br /&gt;&lt;br /&gt;      Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)&lt;br /&gt;      ActionMailer::Base.smtp_settings = {&lt;br /&gt;        :address =&gt; "smtp.gmail.com",&lt;br /&gt;        :port =&gt; "587",&lt;br /&gt;        :domain =&gt; "gmail.com",&lt;br /&gt;        :user_name =&gt; "example.com,&lt;br /&gt;        :password =&gt; "youraccountpassword",&lt;br /&gt;        :authentication =&gt; :plain&lt;br /&gt;      }&lt;br /&gt;      MailSent.deliver_message(to,msg,sub,from,cc)&lt;br /&gt;    rescue Exception=&gt;e&lt;br /&gt;      puts e&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 13 May 2008 04:08:35 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5486</guid>
      <author>jmanivannancse (manivannan)</author>
    </item>
    <item>
      <title>Using POP3 to Retrieve Email for Rails App</title>
      <link>http://snippets.dzone.com/posts/show/4214</link>
      <description>Put this in a file called "inbox" in the scripts/ directory of your Rails app. change the host, username, and password to match.&lt;br /&gt;&lt;br /&gt;Set up a cron job to run this script every so often (frequency depends on your needs).&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/env ruby&lt;br /&gt;&lt;br /&gt;require 'net/pop'&lt;br /&gt;require File.dirname(__FILE__) + '/../config/environment'&lt;br /&gt;&lt;br /&gt;logger = RAILS_DEFAULT_LOGGER&lt;br /&gt;&lt;br /&gt;logger.info "Running Mail Importer..." &lt;br /&gt;Net::POP3.start("localhost", nil, "username", "password") do |pop|&lt;br /&gt;  if pop.mails.empty?&lt;br /&gt;    logger.info "NO MAIL" &lt;br /&gt;  else&lt;br /&gt;    pop.mails.each do |email|&lt;br /&gt;      begin&lt;br /&gt;        logger.info "receiving mail..." &lt;br /&gt;        Notifier.receive(email.pop)&lt;br /&gt;        email.delete&lt;br /&gt;      rescue Exception =&gt; e&lt;br /&gt;        logger.error "Error receiving email at " + Time.now.to_s + "::: " + e.message&lt;br /&gt;      end&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;logger.info "Finished Mail Importer." &lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 26 Jun 2007 17:40:30 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4214</guid>
      <author>timmorgan (Tim Morgan)</author>
    </item>
    <item>
      <title>Simplifying ActionMailer development in Ruby on Rails</title>
      <link>http://snippets.dzone.com/posts/show/1338</link>
      <description>Sick of writing almost the same thing over and over in your ActionMailer classes? Skip all that, and use something like this.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;class Mailer &lt; ActionMailer::Base&lt;br /&gt;&lt;br /&gt;  helper ActionView::Helpers::UrlHelper&lt;br /&gt;&lt;br /&gt;  def generic_mailer(options)&lt;br /&gt;    @recipients = options[:recipients] || "me@privacy.net"&lt;br /&gt;    @from = options[:from] || "me@privacy.net"&lt;br /&gt;    @cc = options[:cc] || ""&lt;br /&gt;    @bcc = options[:bcc] || ""&lt;br /&gt;    @subject = options[:subject] || ""&lt;br /&gt;    @body = options[:body] || {}&lt;br /&gt;    @headers = options[:headers] || {}&lt;br /&gt;    @charset = options[:charset] || "utf-8"&lt;br /&gt;  end&lt;br /&gt;  &lt;br /&gt;  # Create placeholders for whichever e-mails you need to deal with.&lt;br /&gt;  # Override mail elements where necessary&lt;br /&gt;  &lt;br /&gt;  def contact_us(options)&lt;br /&gt;    self.generic_mailer(options)&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt;  ...&lt;br /&gt;&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;(If you have a configuration loaded into a constant, you could just replace the defaults above and use your app's defaults to make it all cleaner, of course)&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;And then from your controller you can do stuff like this:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;Mailer.deliver_contact_us(&lt;br /&gt;   :recipients =&gt; "x@x.com",&lt;br /&gt;   :body =&gt; { &lt;br /&gt;               :name =&gt; params[:name],&lt;br /&gt;               :phone =&gt; params[:phone],&lt;br /&gt;               :email =&gt; params[:email],&lt;br /&gt;               :message =&gt; params[:message]&lt;br /&gt;             },&lt;br /&gt;   :from =&gt; "y@y.com"&lt;br /&gt;)&lt;/code&gt;</description>
      <pubDate>Thu, 02 Feb 2006 08:20:25 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1338</guid>
      <author>peter (Peter Cooperx)</author>
    </item>
  </channel>
</rss>
