Oct 29

 Sending emails is easy. All you need is access to an SMTP server. Or local Sendmail daemon. Installing and configuring either of the two is a massive task. Even if you get it right, your ISP might not like you running SMTP server. If you are past ISP hurdle, chances are your emails will get marked as SPAM for lack of Reverse DNS.

This is an easier way and we all know it – just use Google SMTP server. All you need is a gmail account or Google Apps account – and who doesn’t have a google account?

However, sometimes, the third party software you’re trying to configure to send emails doesn’t support anything other than localhost. Or it does but wants plain SMTP whereas Google does only TLS. Or simply, connecting to Google’s SMTP for each email takes few seconds and you want faster response.

Here’s a simple solution:

  • Install the wonderful Email Relay program from here
  • Create a file :
    vi /etc/google.email.auth

    and add following line: 

    • login client yourgoogleemailid@gmail.com yourgooglepassword
  • chown daemon:root /etc/google.email.auth
    chmod 400 /etc/google.email.auth
  • run emailrelay as:   
    emailrelay --as-proxy smtp.gmail.com:587 --client-tls --client-auth /etc/google.email.auth
  • Configure your software to use localhost for SMTP server (Port defaulted to 25).

Test your Local Emailer. If it doesn’t work, enable logging in /etc/emailrelay.conf by uncommenting verbose line and look into your syslog file (/var/log/syslog)

Tagged with:
Sep 13

If you run your asterisk behind Firewalls (which you probably do), you might run into issues with your ISP blocking outgoing Emails from your Asterisk Box. Here’s a simple solution which lets you use the Gmail servers instead, eliminating these issues.
Steps to use Gmail for Asterisk here

Few simple notes :

  1. You can use your Google Apps Account too. Just use your full Email as username , eg. john@mycompany.com
  2. Make sure the Asterisk hostname as reported by ‘hostname’ command is in /etc/hosts – on the line with 127.0.0.1 as IP address – otherwise, sendmail would take few minutes to start and send emails.
Tagged with:
Jul 23

Like many small businesses, we use Google Apps for all our Email and Collaboration needs and Firefox being our preferred browser, we’d wanted to teach Firefox to use our Google Apps email to send emails by default. Here are the steps I found from a quick google search :

  1. Open up Firefox
  2. type about:config in the address bar and click on ‘I promise’ button to continue.
  3. in the Filter box, type: gecko.handlerService.allowRegisterFromDifferentHost
  4. If the value is set to False, double click on the line to turn it to ‘true’
  5. in the address bar again, copy and paste these : javascript:window.navigator.registerProtocolHandler(”mailto”,”https://mail.google.com/a/yourdomain.com/mail/?extsrc=mailto&url=%s”,”Google Apps”)
  6. Remember to replace yourdomain.com with your domain. Also, make sure those are double quotes. After pasting into the address bar, just delete each double quote character and retype them as double quote again – to be sure.
  7. Hit Enter while still in the address bar.
  8. Goto Edit/Preferences or Tools/Options – depending upon your version of Firefox
  9. Goto Applications
  10. Find ‘mailto’ in the list and click on the dropdown – it should now have an entry called ‘Google Apps’. Pick this, click Close.
  11. Goto a website and pick File/Send Link – it should open up your Google Apps email (assuming you’re already logged into the Google Apps account).
    Tagged with:
    Jun 12

    Apparently, merb’s approach to sending email is far better than ActiveMailer. However, I still find it quite annoying and heavyweight for simple applications. And most of the email notifications sent from web applications tend to be simple. In order to send emails via Merb, you need to create mailer views and mailer controllers and pass parameters between them carefully. I, for sure, always get confused which parameters to pass where and how incoming parameters get be exposed to the mailer view templates.

    Here’s a simple routine to send emails right from within your merb controllers. Or any other place, for that matter.

     
     gem install mailfactory
     gem install smtp_tls # if you need authentication or 
                                #want to use google smtp.
                                # A quick google search will find it.
    # start sending emails:
    require 'mailfactory'
    require 'net/smtp'
    mail             = MailFactory.new
       mail.from      = 'your@company.com'
       mail.subject  = 'Test'
       mail.html       = 'html mail body'
       mail.text       = "mail text , if it's not html"
       mail.replyTo   = 'noreply@company.com'
       # repeat next line for each attachment
       mail.attach_as(file_path, 'filename to attach as', 'application/pdf')
    Net::SMTP.start(
      'smtp.host.com',
      25,
      'from@domain.com',
      'smtp username',
      'smtp password',
      'plain' # authentication method
    ) do |smtp|
    smtp.send_message(mail.to_s, 'from@address.com', 'to@address.com')
    end

    I find this simpler since it’s encapsulated in one place. No need to create multiple files and impose entire MVC paradigm for sending emails. Let’s KISS.

    Tagged with:
    preload preload preload