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!



佐藤優 ─ 前日本駐俄羅斯外交官,外語除英語外精通捷克語, 韓語及俄羅斯語。初中前讀書量極少,主要看電子類書籍及文學小說。初一後嘗試接觸不同類型書籍,後來在大學研讀神學書和哲學書。現時一個月平圴能讀 300 本,狀態更好能達 500 本。每天需要處理超過 2500 頁 A4 文件,轉換成書的話大概一天要讀完 5 本。

習慣讀書人仕平圴一個月僅可「熟讀」 5 本 ,一年即 60 本,一生才大概 3000 本。由於一生人可以讀的書很有限,因此「速讀」變得非常重要。

速讀守則 :

  1. 必需對該範圍的基礎知識相當穩固,否則只能「熟讀」
  2. 只需要看未懂或新知識的部分
  3. 速讀不是瀏覽


  1. 以奇數數目選擇書本,例如 3 本 , 5 本。因為作者間的觀點若果出現衝突,可以採取多數決解決問題,避免進入兩難局面浪費時間。
  2. 試閱書的中間章節,那是書最脆弱的部分。
  3. 集中精力閱讀學術類書籍的最後部分,因為那是作者對該理論總結其證明最有力的部分。
  4. 需要「弄污」書籍做筆記,借用圖書館書籍就不能做,故此建議花點錢買書。
  5. 看書時用鉛筆以方框圈著重要的段落,不宜超過總頁數的 10分1;重要的書頁可以拆角或貼上標籤。
  6. 遇到不明白的地方以 “?” 標注;在書內對作者的觀點寫下個人意見,判斷,一至兩句即可。
  7. 利用方框圈點的重點製作筆記。若果解決了當初不明白的地方,可以把標記擦去。
  8. 同一本書需讀最小 3 次。


  1. 超速讀 (5 分鐘),並無需做筆記
  2. 普通速讀 (30 分鐘),做小量筆記
  3. 熟讀 ,做深入筆記