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!

ISCSI 設定筆記 (2): Ubuntu 上使用 Initiator 連接 ISCSI Target

尋找指定 IP 的 ISCSI Server 所提供的 ISCSI Target :

iscsiadm -m discovery -t sendtargets -p


iscsiadm -m node -p -o show


iscsiadm -m node -p -o update -n <name> -v <value>


iscsiadm -m node -p --op=update --name=<name> --value=<value>


iscsiadm -m node -p -T "" -o update -n node.session.auth.authmethod -v CHAP
iscsiadm -m node -p -T "" -o update -n node.session.auth.username -v username
iscsiadm -m node -p -T "" -o update -n node.session.auth.password -v password

開機自動連接這個 target:

iscsiadm -m node -p -o update -n node.conn[0].startup = automatic


iscsiadm -m node -p --login


Logging in to [iface: default, target:, portal:,3260] (multiple)
Login to [iface: default, target:, portal:,3260] successful.


iscsiadm -m node -p --logout

若果剛才入登錄成功,在終端機中輸入以下指令即可查閱該 target 的磁碟資訊:

 fdisk -l 

SAN/iSCSI/open-iscsi – Debian Wiki

Ubuntu 12.04 LTS – Configure iSCSI Initiator : Server World

Ubuntu 12.04 LTS – Configure iSCSI Target : Server World

ISCSI 設定筆記 (1): Ubuntu 上架設 ISCSI Server

最近改動一下備份方案,打算掛載多個 iscsi targets 作備份之用,並且順便寫份筆記做個記錄。

利用 ssh 連接到 ubuntu server ,輸入以下指令找出建立 iscsi target 的磁碟:

fdisk -l


Disk /dev/sda: 256.1 GB, 256060514304 bytes
255 heads, 63 sectors/track, 31130 cylinders, total 500118192 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x000cca3d

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      499711      248832   83  Linux
/dev/sda2          501758   500117503   249807873    5  Extended
Partition 2 does not start on physical sector boundary.
/dev/sda5          501760   500117503   249807872   8e  Linux LVM

Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes
81 heads, 63 sectors/track, 382818 cylinders, total 1953525168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000abc

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048  1953525167   976761560   83  Linux

在 sdb1 上建立 physical volume :

pvcreate /dev/sdb1

查看一下 server 上 physical volume(s) 的資訊:


新增 1 個 volume group:

vgcreate vg_target0 /dev/sdb1

如同 pvdisplay, 輸入以下指令即可查看 本機 volume group(s) 資訊:


新增 1 個 100Gb 的 logical volume:

lvcreate -L 100G -n lv_target0 vg_target0

查看這個 LV:



vim /etc/iet/ietd.conf


	LUN 0 Path=/dev/vg_target0/lv_target0,Type=blockio	
	incominguser username password
	alias LUN1


service iscsitarget restart

Using iSCSI On Ubuntu 10.04 (Initiator And Target) | HowtoForge – Linux Howtos and Tutorials

酷爾的家: 在Ubuntu 使用 iSCSI Initiator

鳥哥的 Linux 私房菜 — 網路磁碟裝置:iSCSI伺服器

ASP.NET MVC3 Project on Mono

剛才成功把一個 MVC3 的 Project 移植到 ubuntu 上運行。

  1.  Mono 需要到這3個 assemblies 組件。逐一按  “Add Reference” 加入到 Project 中。
  2.  Mono 沒有以下assemblies 組件,需要在Visual Studio滙出。按下列組件,在Properies 視窗中把 Copy Local 設成 “True”。
  3. Mono 對以下assemblies 組件不相容。按下列組件,再按Delete 刪除。
  4. 按build 進行編譯,然後把專案複製到 ubuntu 。
  5. 使用 MonoDevelop 開啓這個專案 。這時你需要把錯掉了的 References 刪除 (Step 2),然後重新加入 正確路徑的 References。按 “Edit References”  選  “.Net Assembly” ,進入 Output Directory 然後加入下列組件

    按 build 進行編譯,沒錯的話代表移植成功

  6. xsp4 是 mono 的 development web server , 用來運行 ASP.NET 專案。在terminal 中輸入以下指令安裝 xsp4:
    sudo apt-get install mono-xsp4

    要啓動 Web Server,先把 termial 切換路徑至專案中 ,然後輸入 “xsp4″即可

ASP.NET – Mono
ASP.NET MVC3 Support
Deploying your ASP.NET MVC3 site on Mono

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 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 &

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