Gmail + Postfix on Ubuntu 14.04

if I tell you that the draft of this article has already existed for 400 days (more than a year)! You may wonder how ridiculous I am to not finish it earlier. Okay, the fact is that I put too much things inside one article. Now, I plan to break it up into a series of articles.

In this article, you will know how to setup a free Gmail Relay on your ubuntu server. There maybe quite a lot of online resources to do the simliar thing, but I prefer to write my own as a example and to refresh my forgetful brain. 😀

Installing Postfix

Install Postfix using the following command:

sudo apt-get install postfix

You will see this prompt at some point. Select Internet Site.

Screenshot from 2016-04-13 22:43:47

Screenshot from 2016-04-16 17:07:18

Postfix Configuration

Once the installation is finished, change your terminal’s current directory to


Configure Gmail account and password

create a file call gmail_passwd, replace the information with your credentials.


execute the following command to generate a postfix database.

sudo postmap /etc/postfix/gmail_passwd

For safely reason, you should allow only the root user can access this 2 files.

sudo chown root:root /etc/postfix/gmail_passwd /etc/postfix/gmail_passwd.db
sudo chmod 0600 /etc/postfix/gmail_passwd /etc/postfix/gmail_passwd.db

 Configure your Relay Server

open /etc/postfix/ with whatever editor you like:

vim /etc/postfix/

add the following line to map your credentials

smtp_sasl_password_maps = hash:/etc/postfix/gmail_passwd

Enable TLS and sasl authiencation for Gmail SMTP Server

smtp_use_tls = yes
smtp_sasl_auth_enable = yes

Gmail SMTP Server does not support postfix’s security options. Reset them by:

smtp_sasl_security_options =

Relayhost field means the SMTP relay host. Please put the GMail SMTP server address here. Make sure this address is identical to the one in gmail_passwd

relayhost = []:587

here is the complete version of the

# See /usr/share/postfix/ for a commented, more complete version

# Debian specific: Specifying a file name will cause the first
# line of that file to be used as the name. The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

# TLS parameters
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_use_tls = yes
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtp_sasl_password_maps = hash:/etc/postfix/gmail_passwd
smtp_sasl_auth_enable = yes
smtp_sasl_security_options =
# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = office-local
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mydestination = office-local, localhost.localdomain, , localhost
relayhost = []:587
mynetworks = [::ffff:]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all

reload the configuration:

service postfix reload 

check the status by:

tail -f /var/log/mail.log

check mail.err if there is any error. This file may not exist if there is no error, or it is the first time of you to configure mail related service.

tail -f /var/log/mail.err

Gmail Account Setting

Screenshot from 2016-04-16 16:34:10

Postfix may not works with the default security level of Gmail. Please turn on the “allow less secure apps” option via this link:


mailx is a popular utility in Linux World for sending and receiving mail in terminal. Execute the following command to install it.

sudo apt-get install mailx

Now you can test your postfix configuration by sending a mail to someone. Replace with a valid email address.

echo "Hello Body" | mail -s "Hello Subject" -a

If it was sent successfully, you should see this in the mail.log:

Apr 16 08:41:57 office-local postfix/smtp[1274]: 1603753E: to=<>,[]:587, delay=1723, delays=1720/0.01/1.4/0.85, dsn=2.0.0, status=sent (250 2.0.0 OK 1460796117 h5sm69972904pat.0 - gsmtp)
Apr 16 08:41:57 office-local postfix/qmgr[1197]: 1603753E: removed

 Trouble Shooting

Apr 16 08:27:23 office-local postfix/smtp[1007]: E81E93C5: to=<>,[]:587, delay=7, delays=0.01/0.01/7/0, dsn=4.7.14, status=deferred (SASL authentication failed; server[] said: 534-5.7.14 < qQtdCND0kjQn0lwMS5NJc9nXMTotKJG76X83IjhjNi5jaGjyZed5WfHf_Rm0SxoaiwFAAU?534-5.7.14 tvpINwFpyp2YOKpYmEnCnlmUn33voaf7jG8lN71043p3bgcKNY8Zqk2WB-zKKEoWW58zkM?534-5.7.14 uwn5lZcHpxEJvx5HXAEf0MQcOu_EVJLEFByoP35IPcKquJM5qnI4nBVGzFD93uC6IaSxDH?534-5.7.14 DhDeKmFa94G2XQXZItNqqLtrW8Yco> Please log in via your web browser and?534-5.7.14 then try again.?534-5.7.14 Learn more at?534 5.7.14 n74sm69735534pfa.45 - gsmtp)

your Gmail account is not allow less-secure apps to sign-in



Configure Postfix to Use Gmail SMTP on Ubuntu


OneTab keeps crashing

It was just a normal day, a day similar to others.  My OneTab was suddenly not working. Some people here might not know it, OneTab is a chrome extension that make keeping and restoring tabs easy.

Screenshot from 2016-04-06 18:04:16.png

Honestly , I didn’t get surprised. Why?

I have a habit of keeping lots of tabs open in multiple windows. In a regular day, I can open up to 30+ tabs easily. That’s why I need some tools like OneTab to manage all of them. Also, I keep all the lists even they are restored. This led to that over the past 2 years, I have 4k+ tab records inside the OneTab.

The reason is simple, when I open up the OneTab page, I have a sense that it becomes slower and slower, it’s because there are too many items in the page which may cause a memory leak. What’s worse is that I can’t even remove and export the data!

So, what can I do?

Popular Linux Distro mostly is storing the data of the chrome extensions under the following path:

 /home/{YOURNAME}/.config/google-chrome/Default/Local Storage

For each extensions, there would be a .localstorage file and a .localstorage-journal file. One tab is stored as:



In fact, those .localstorage files are just SQLite files. Fortunately I can solve it by doing some DB operations.

To make life simpler, I do it in GUI. Thanks to the author of sqlitebrowser.

Screenshot from 2016-04-12 00:36:38.png

Screenshot from 2016-04-12 00:37:462.png

Basically, it’s just a simple database containing 1 key-value table only. There are 7 records in this table but only 2 records, idCounter and state, are matters.

  • idCounter: the last primary key of tabs
  • state: the tabs records that stored in JSON string

Copy and paste the value of “state” to any editor, you should see something like this:

  "tabGroups": [
      "id": 3198,
      "tabsMeta": [
          "id": 3182,
          "url": "http://localhost:3000/users/75/edit",
          "title": "Servlet Error"
          "id": 3183,
          "url": "",
          "title": "3.8 Procedure Expressions: lambda and case-lambda"
          "id": 3185,
          "url": "",
          "title": "10.2 Exceptions"
          "id": 3188,
          "url": "",
          "title": "6.4 Field and Method Access"
          "id": 3197,
          "url": "",
          "title": "condition - application: not a procedure racket - Stack Overflow"
      "createDate": 1453743658563
      "id": 3212,
      "tabsMeta": [
          "id": 3199,
          "url": "",
          "title": "10.2 Exceptions"
          "id": 3200,
          "url": "",
          "title": "5.1 Defining Structure Types: struct"
      "createDate": 1454092984398

It’s Just a pure Json data. I make a copy of this for backup purposes. Now I can remove some items here. I did few tests to find the recommended size, I prefer to limit to 1000. Besides that make sure the id of the last item is the same as the value of idCounter in itemTable.

Data is ready, But …

You can’t make this patch work if chrome is running. Basically, all the chrome’s instances must be terminated before you are touching the extension data. To do so, you might use some commands like: kill, top or htop, etc.

Finally just replace the state field of itemTable with the modified version of the json data. And of course, OneTab is back!

Tor for chrome in ubuntu

忙中偷閒寫個script. Tor for chrome in ubuntu
設好 TORPATH 基本上可馬上用

#!/bin/bash # >> ------------------------------- # tor for Chrome version 1.0 # By: SiuTin # Date: 26,April 2012 # Website: # ------------------------------- << # set tor path TORPATH=~/tor-browser_en-US echo "=> TOR FOR CHROME" # set port.js path PREFSJS=$TORPATH/Data/profile/prefs.js # get dynamic port number PORT=$(cat $PREFSJS | grep network.proxy.socks_port | egrep -e '([0-9])+' -o) # combine address and port ADDR=$PORT echo "=> TOR ADDESS = $ADDR" echo "=> starting chrome ...." # run chrome /usr/bin/google-chrome --proxy-server="socks://$ADDR;socks4://$ADDR;socks5://$ADDR;"

在 ubuntu 上安裝 Node.js

在 ubuntu 上安裝 Node.js

  1. 安裝所需元件

    	apt-get install -y make git git-core g++ curl libssl-dev apache2-utils python
  2. git clone 資料

    	git clone && cd node
  3. *.安裝前最好轉到 v0.6.3+ ,否則將會出現 `make install` is not implemented yet. Bug bnoordhuis about it in #node.js 這個錯誤 。

    	git tag -l
  4. 選個最新的 ( 以安裝時計算,最新版本為 v0.6.5 )

    	git checkout v0.6.5
  5. 最後下這句

    	./configure && make && make install