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 keep 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 store 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 only 1 key-value table. 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 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!

Install Apache 2.4.9 on Mac OSX 10.9 Mavericks

1. install homebrew

ruby -e "$(curl -fsSL"

2. install dependencies

brew install pcre
brew install libtool

3. download apache 2.4.x version

4. extract it and then go into the directory

tar zxvf httpd-2.4.9.tar.bz2 && cd httpd-2.4.9

5. after that run the following to confgure:

./configure --prefix=/usr/local/apache-2.4.9 LTFLAGS=--tag=cc

6. if you can’t complie because of llvm-gcc/gpp issue, install the GNU/gcc:

brew install gcc46

7. run the following command should work fine:

./configure --prefix=/usr/local/apache-2.4.9 CC=/usr/local/Cellar/gcc46/4.6.4/bin/gcc-4.6 CPP=/usr/local/Cellar/gcc46/4.6.4/bin/cpp-4.6 LTFLAGS=--tag=CC

8. after the configuration, build it:


8. and install it:

sudo make install

9. Then, we can create symbolic links:

sudo ln -s /usr/local/apache-2.4.9 /usr/local/apache
sudo ln -s /usr/local/apache/bin/httpd /usr/sbin/httpd
sudo ln -s /usr/local/apache/bin/apachectl /usr/sbin/apachectl

10. start apache server:

sudo apachectl start


sudo httpd -k start

11. check apache version:

sudo httpd -v


Server version: Apache/2.4.9 (Unix)
Server built: Jun 11 2014 16:18:15


sudo apachectl status


Apache Server Status for localhost (via ::1)

 Server Version: Apache/2.4.9 (Unix)
 Server MPM: worker
 Server Built: Jun 11 2014 16:18:15

 Current Time: Thursday, 12-Jun-2014 00:45:38 HKT
 Restart Time: Thursday, 12-Jun-2014 00:42:42 HKT
 Parent Server Config. Generation: 1
 Parent Server MPM Generation: 0
 Server uptime: 2 minutes 56 seconds
 Server load: 1.86 1.67 1.69
 Total accesses: 1 - Total Traffic: 2 kB
 CPU Usage: u0 s0 cu0 cs0
 .00568 requests/sec - 11 B/second - 2048 B/request
 1 requests currently being processed, 74 idle workers


 Scoreboard Key:
 "_" Waiting for Connection, "S" Starting up, "R" Reading Request,
 "W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup,
 "C" Closing connection, "L" Logging, "G" Gracefully finishing,
 "I" Idle cleanup of worker, "." Open slot with no current process

12.  if you get ‘Not found ‘ error as below:

Not Found
The requested URL /server-status was not found on this server.

because the mod_status module is not configured, so add the following lines to httpd.conf:

<IfModule mod_status.c>
   # Allow server status reports generated by mod_status,
   # with the URL of http://servername/server-status
   # Change the "" to match your domain to enable.
   <Location /server-status>
     SetHandler server-status
     Order deny,allow
     Allow from all

Finally restart the apache server, it should work properly!


解決 Git 不能 push 的問題

我的 Windows 不知幹什麼了,一直以來都有個很奇怪的 Git 問題。用 Git Gui 可以輕鬆就 Push 到 Remote Repository ,但在 Git Bash 或者是 Gui Extensions 就出現了 fatal :the remote end hung up unexpectedly 的錯誤。後來研究 Nodejs 連系統都轉用 Ubuntu ,這個問題便不了了之。最近有個專案使用到 MVC3 ,重歸 Windows 後不能自如地 push ,就整個很不爽了。今天終於找到解決方法,問題在於SSH client。

  1.  開啓 Git Extensions 後按 Settings > Ssh
  2. 在 Specify which ssh client to use 中選擇 Other ssh client
  3. 在右邊的方格找出 ssh 路徑 ,通常是 C:\Program Files (x86)\Git\bin\ssh.exe

按確定後開啓 Git Bash ,輸入 git push ,錯誤訊息不再出現了。

GoPro HD HERO Firmware Update

友人說他的GOPro升級後開機沒反應,似乎是變磚了,問我怎辦。我看了看官方升級的方法,也跟手做一次,的確不行。於是到GOOGLE 搜一下,看看有沒有同類問題的朋友。


網民 iKapture 說他的解決方法如下:

Make sure that you have transferred the uncompressed firmware file to your SD Card = firmware.bin / should be 8.2mb once uncompressed

step 1. I took out the SD Card and then the battery after first removing the USB cable. Once I had everything removed and definitely no power I held the power button for at least 2sec to allow all of the stored energy to be expelled.
step 2. Install the battery (fully charged) and the battery cover (no USB card yet), once these were installed I pressed the power button and the camera started
step 3. Power down the camera and installed the SD Card.
Step 4. Hold the shutter button down and press the power button at the same time continuing to hold the shutter button. Make sure that the camera starts (i.e. it says 000 on the LCD screen)
step 5. With the camera started completely and still holding the shutter button press the power button 3 times in succession. This will then show UP in the LCD screen and the firmware will start uploading this should take 3seconds or more.
step 6. The camera will automatically shut down, once shut down release shutter button and re-power the camera.

Once you have confirmed that the camera restarts you can power it down and attach the LCD back and the new rear cover for the housing.

充滿電後再跟著做一次,GOPRO 成功開機了!呵呵!

在 ubuntu 11.10 上安裝 Xspim/QtSpim – MIPS32 Simulator

學校裡某個課程是關於 MIPS Architecture, 邊使用 emulator 邊看書有助學習。Course page 提到了 Spim simluator 。在官方網站看了一遍,除了window version 外 spim 還支援 Linux / mac。並且提供了三個 GUI 版本:

  • Xspim (Xwindow)
  • PCSpim (Microsoft Window)
  • Qtspim  (Qt Library)

Xspim 和 PCSpim 都非常舊,官方推薦使用 Qtspim。不過在這裡我會把 Xspim 及Qtspim 的安裝過程都記錄下來。

花了點時間安裝,平台是 ubuntu 11.10。


1. 在 Ubuntu Software Center 中搜尋 xspim 並且 按 install 安裝

2. 安裝完成後,在 terminal 鍵入:





3. 成功啟動方法如下:

xspim -font 6x10



1. QtSpim 沒有 For Ubuntu 的套件,需要自已Build。利用SVN 下載 Source Code,在Terminal 上回到home directory ,然後鍵入 :

svn co spimsimulator

2. 下載 Qt Sdk version 4.8 32bit 64bit for linux
切換到 Qt Sdk的目錄下輸入:

chmod u+x



3. 安裝完成後,運行 QtCreator 並且開啟專案,路徑如下:


4. 按一下 build 按鈕,QtCreator 開始編譯。

5. 編譯了的程式放在這裏:


6. 在 Terminal 切換至上述路徑, 啟動Qtspim :

./QtSpim &

成功運行,可以專心學習了 !

如何將PC 轉成 VM

最近買了acer aspire one 255e 代替了那台用了差不多快6年的eeepc 901,然後這個越用越慢的東西被我封塵了一個多月。這台SSD應該要快掛了,於是今天便做個備份,把整台機轉成VM。

在 host PC 上安裝 VMware vCenter Conveter ,以remote machine 方式連接 eeepc 901 不成功,似乎是出現了permission problem。

google 了一下,找到了出現相同問題的朋友

根據mediawideCasaDelGato的解決方法,我在eeepc 上使用  VMware vCenter Conveter 以local machine 方式做轉換,並且mapping drive 把VM 放到host PC 上。


FAILED: Undable to create a VSS snapshot of the source volume(s). Error 2147754758 (0x80042306).


1. 啓動服務   Microsoft Software Shadow Copy Provider Service  , Volume Shadow Copy Service

2. 把source machine 的 Harddisk 格式轉成  NTFS


FAILED : Unable to find the system volume,reconfiguration is not possible.

這個原來是 boot.ini 出問題,因為轉到了vm machine 設備都不同了,要打開它做修改。

這時最好掛上這個 vmdk file 到已有的VM,再做修改。