Click or scroll down Circle me on Google+ Fork me on GitHub Follow me on Twitter Ask me on Stack Overflow Gild me on Reddit Code Ninja, Entrepreneur, Idiot ChalkHQ — consulting, prototyping, mentoring — resolve innefficiencies in your startup's workflow — online open-mic / creative space The Dirac Equation (click to WikiPedia) A maxim Sun Tzu references in his magnum opus The Art of War

If you know the enemy and know yourself, you need not fear the result of a hundred battles.
If you know yourself but not the enemy, for every victory gained you will also suffer a defeat.
If you know neither the enemy nor yourself, you will succumb in every battle.
Fork me on GitHub


actionscript ad-hoc networks Adobe AIR anonymous Apple array Browsing convert Debugger Error Facebook file permissions Flash Flex fonts function future Google Google Plus grid hackers html javascript logs loop network p2p php privacy regexp Security Server social ssl technology terminal time Twitter upgrade Web 2.0 Web 3.0 Web 4.0 Web 5.0 wordpress

Featured Posts

  • Javascript: Undefined parameters
  • The Web, A Look Forward
  • Let Postfix send mail through your Gmail Account – Snow Leopard
  • Archives

  • April 2013
  • December 2011
  • July 2011
  • June 2011
  • March 2011
  • February 2011
  • January 2011
  • November 2010
  • October 2010
  • September 2010
  • July 2010
  • May 2010
  • Categories

  • Code
  • Design
  • Opinion
  • Security
  • Tools
  • Uncategorized
  • Let Postfix send mail through your Gmail Account – Snow Leopard

    First of all GRRRRRR!!

    Second, this has been one of those things I randomly get sucked into between projects where I'll spend 5 hours on Google trying to figure it out and getting tiny fragments of info but never actually solving the issue. This is the worst! What the hell am I talking about? Say you use MAMP or whatever as a local testing server. You write some PHP and you need to use the mail() function. You test your new email function to your personal gmail account. Ok so you try it and it doesn't work, or even worse it works a couple times and then never again.  So you go to Applications->Utilities and fire up the Console application. You're shocked to see that there's a message in there saying something about Gmail not accepting mail from your IP address because it's registered as a residential thingy and apparently a lot of spammers use their personal computers to send spam.

    So you say no no there must be some mistake I'm a programmer, not a spammer, I'm just trying to test out my new app. But you quickly realize you're talking to a computer, pleading, and well it doesn't care. typical. After, you cry and try piece together a coherent step by step set of instructions to route all mail sent from your computer through your Gmail account - so it would be from you, and all go through. here's what you do.

    note that $ is used to show a new terminal command, you don't actually type it in:

    Open Terminal - found in Applications->Utilities and type in:

    $ sudo nano /etc/postfix/relay_password

    You'll now be editing a new file called relay_password in the nano Terminal editor, type in the following substituting your login info - it should work with google apps accounts as well:

    Press ctrl+o on your keyboard followed by Enter to save the file, then press ctrl+x to exit the editor.

    Now type in:

    $ sudo postmap /etc/postfix/relay_password

    That should tell Postfix to use the relay file you just created. Gmail uses a secure connection so you need to head over to Verisign and download some root certificates. Go to the following url fill out your info and download the .zip file:

    Now type in the following commands one after another. In the second command it wants the you just downloaded, you can just drag the zip file onto the Terminal window and it will fill in it's location, don't do that for the 4th command though. Also note you may have some certificates already on your system, so after the second last command you may be prompted to replace existing certificates, type N so it doesn't replace the ones you have:

    $ sudo mkdir /etc/postfix/certs
    $ sudo cp /etc/postfix/certs
    $ cd /etc/postfix/certs/
    $ sudo unzip -j
    $ sudo openssl x509 -inform der -in thawte\ Primary\ Root\ CA\ -\ G2_ECC.cer -out thawte\ Primary\ Root\ CA\ -\ G2_ECC.pem
    $ sudo c_rehash /etc/postfix/certs

    Now type in:

    $ sudo nano /etc/postfix/

    Go to the end of the document, you can delete the MAMP stuff, also note that if you have MAMP Pro and you edit postfix settings from there it'll fuck up what we're doing here. So remember this going into the future and don't do that.

    Paste in the following at the end of the document - note: use the keyboard to get around the document, but use the mouse to right click and paste:

    relayhost =
    # auth
    smtp_sasl_auth_enable = yes
    smtp_sasl_password_maps = hash:/etc/postfix/relay_password
    smtp_sasl_security_options = noanonymous

    # tls
    smtp_tls_security_level = may
    smtp_tls_CApath = /etc/postfix/certs
    smtp_tls_session_cache_database = btree:/etc/postfix/smtp_scache
    smtp_tls_session_cache_timeout = 3600s
    smtp_tls_loglevel = 1
    tls_random_source = dev:/dev/urandom

    Save it like we did before by pressing ctrl+o, then Enter, then ctrl+x.

    Now type in:

    $ sudo nano /etc/postfix/

    You're now editing, this is a different file to we just pasted stuff into. There should be a table in here, find the line in the table that looks something like this:

    #tlsmgr    fifo  -       -       n       -       1       tlsmgr

    Make it look like this - note the comment is removed and fifo should be unix:

    tlsmgr    unix  -       -       n       -       1       tlsmgr

    Save it like the other times pressing ctrl+o, then Enter, then ctrl+x.

    Ok, so at this point you can put the following into terminal and see that it works - put your email address in there twice:

    printf "Subject: blah" | sendmail -f

    Postfix is working now. good. You go back to your PHP application and test the mail()function again. If it works then you're done, but if not you panic. You start feeling really hungry. You know that Postfix is working but maybe PHP or Apache haven't gotten the message yet. ok. So you see in Console that sendmail is crashing, you open the crash report in Terminal and it tells you there's an incompatible version of libxml. It wants 10 and you have 9. You begin questioning if any of this is worth it and maybe you should just go sit in front of a tv and forget about doing anything meaningful with the rest of your life.

    After almost installing XCode and registering as an apple developer so you can make and install the newest version of libxml, you wonder if maybe MAMP comes with libxml and find that yes it does. So instead of spending 2 hours upgrading the system libxml only to find it doesn't do anything you just upgrade to the latest version of MAMP (1.8 at the time of writing) and it works. What?? it works? really? yup. so what do you do now?

    REJOICE! with lunch.

    Some of this was scoured from random forums and blogs in the midst of complete frustration and combined into steps that actually work. A chunk however was taken from this post: so check them out.


    Category: Tools

    Tagged: , , , , , ,

    • Dylancaseyjohnson

      spectacular job. i’ve been fighting with this issue all day, and i’m a complete amateur. your explanation was concise and clear enough for me to understand and apply. thanks very much for posting this.

    • Danl18

      You are the man!! Thank you for this!

    • Daniel

      awesome!  thank you!

    • Dominic

      i did everything you said, and it doesnt work, I keep getting this, 5.7.0 Must issue a STARTTLS command first. s3sm727282pbg.93 (in reply to MAIL FROM command) Help?? Please.

    • Govinda

      I went through several forums/blog posts.. beat my head.. and only finally with this got mail working, and with gmail..  sweet.   ‘Thanks you’ does not seem to cut it.  ;-)

    • Sing

      How did u solve it?

    • Xalexas

       I had same problems. You have to change in

      sudo nano /etc/postfix/

      uncomment tlsmgr and change it to unix instead of fifo. It should be:

      tlsmgr    unix  –       –       n       –       1       tlsmgr

      After that:
      sudo postfix reload

      and you should be fine.

    • Xalexas

       I have wrote complete tutorial somewhat different of this one so you can take a look here:

    • mail and mailx unix to google yahoo not working

      [...] Originally Posted by forumbaba As I said in my first post, there are many posts about this subject already, posts similar to you replies. this kind of posts are not in anyway helpful to the problem described here : which is how to send mail from mailx or mail on mac osx, linux or any unix system. I specifically asked for someone willing to post a DETAILED solution to the probem i.e enumerating what problem they had earlier faced on their system setup and how they solved it step by step If indeed you have come across this problem before, please post what changes you made to you system or your email settings that helped solved the problem (in a clear and simple step by step manner). This is what is required of you and this will be much more helpful. Apparently, you're not understanding what you're being told:Mac OSX IS NOT LINUX. I can tell you how to set up both postfix and sendmail ON LINUX to use a smarthost. Those instructions don't apply to Mac OSX, which is why you were given a link that TELLS YOU HOW TO DO IT.. The first link I sent you has complete instructions here:…-snow-leopard/ [...]

    • Corjen

      Thanks so much!!!

    • axl

      This all looked great… but when I got to the part
      openssl x509 -inform der -in thawte Primary Root CA – G2_ECC.cer -out thawte Primary Root CA – G2_ECC.pem
      I get the followin error:
      Error opening Certificate thawte Primary Root CA – G2_ECC.cer874:error:02001002:system library:fopen:No such file or directory:/SourceCache/OpenSSL098/OpenSSL098-47/src/crypto/bio/bss_file.c:356:fopen(‘thawte Primary Root CA – G2_ECC.cer’,’r’)874:error:20074002:BIO routines:FILE_CTRL:system lib:/SourceCache/OpenSSL098/OpenSSL098-47/src/crypto/bio/bss_file.c:358:unable to load certificateSo now I’m stuck… I followed every step before to the T… Any suggestions?  :)