2015年10月14日 星期三

Roundcube+Dovecot UID MOVE: Mailbox doesn't exist: Trash 解決辦法

Roundcube預設不會直接產生使用者帳號下需要的各個資料夾,當使用者有需求時才會自產生!例如第一次登入時只會有”收件夾”和“寄件備份”兩個資料夾,當使用者刪除信件時,系統會自產生“垃圾桶”這個資料夾,並將刪除的信件放入其中!但某些系統安裝後卻無法自己產生相對應需求的資料夾!便會出現“伺服器錯誤:UID MOVE: Mailbox doesn't exist: Trash”這樣的錯誤訊息!
解決的辦法有兩個:
1.讓Roundcube直接建立預設的資料夾
編輯Roundcube目錄下config資料夾下的config.inc.php檔案,在最下方加入
$config['create_default_folders'] = True;
存檔後使用者再重新登入roundcube即可!

2.編/etc/dovecot/conf.d/20-imap.conf如下,讓dovecot支援自動建立目錄的功能:
mail_plugins = $mail_plugins autocreate

20-imap.conf檔案的最後加上以下內容:
plugin {
autocreate = Trash
autocreate2 = Junk
autocreate3 = Drafts
autocreate4 = Sent
autosubscribe = Trash
autosubscribe2 = Junk
autosubscribe3 = Drafts
autosubscribe4 = Sent
}

存檔後重新啟動dovecot即可!
PS:若dovecot是2.2以上版本,以上設定會導致/var/log/mail.log下出現:
Warning: autocreate plugin is deprecated, use mailbox { auto } setting
這樣的警告訊息!這個警告訊息不影響dovecot的正常運作!
依照Dovecot網頁文件的說法(http://wiki2.dovecot.org/MailboxSettings),dovecot 2.1之後的版本在mail_plugins = 後方不需要autocreate
,所有的autocreate = autosubscribe =  需要移除,並加入下列內容:
namespace inbox { 
#prefix = INBOX. # the namespace prefix isn't added again to the mailbox names. 
# ... 
mailbox Trash { 
auto = no 
special_use = \Trash 
 } 
mailbox Drafts { 
auto = no 
special_use = \Drafts 
 } 
mailbox Sent { 
auto = subscribe # autocreate and autosubscribe the Sent mailbox 
special_use = \Sent 
 } 
mailbox "Sent Messages" { 
auto = no 
special_use = \Sent
 } 
mailbox Spam { 
auto = create # autocreate Spam, but don't auto subscribe 
special_use = \Junk 
 } 
mailbox virtual/All {# if you have a virtual "All messages" mailbox 
auto = no 
special_use = \All 
 } 
}
所以修改完的內容應該如下:
mail_plugins = $mail_plugins 
mailbox_list_index=yes
namespace inbox { 
#prefix = INBOX. # the namespace prefix isn't added again to the mailbox names. 
# ... 
mailbox Trash { 
auto = no 
special_use = \Trash 
 } 
mailbox Drafts { 
auto = no 
special_use = \Drafts 
 } 
mailbox Sent { 
auto = subscribe # autocreate and autosubscribe the Sent mailbox 
special_use = \Sent 
 } 
mailbox "Sent Messages" { 
auto = no 
special_use = \Sent
 } 
mailbox Spam { 
auto = create # autocreate Spam, but don't auto subscribe 
special_use = \Junk 
 } 
mailbox virtual/All {# if you have a virtual "All messages" mailbox 
auto = no 
special_use = \All 
 } 
}
存檔後重新啟動dovecot即可讓dovecot支援自動產生資料夾的功能!但這個做法在目前的roundcube(1.1.4)上並沒有生效!所以建議使用第一個方式來根本解決! 

Ubuntu 14.04下安裝Roundcube1.1.3

安裝好postfix後(安裝步驟參閱ubuntu 14.04 postfix+dovecot+amavis+clamav+spamassassin
),可以加上Roundcube,增加webmail的介面,步驟如下:

1.至Roundcube官網下載Roundcube,將下載的檔案解壓縮後放置你mail 主機下,apache指定的目錄位置,例如/var/www

2.0 安裝需要的元件
sudo apt-get install dovecot-imapd apache2 mysql-server-5.5 php5 phpmyadmin

phpmyadmin可視需求決定安裝與否,若安裝完 phpmyadmin,在登入phpmyadmin時看到畫面下方顯示"缺少 mcrypt 擴充套件。請檢查 PHP 設定。",執行以下指令安裝php5-mcrypt
sudo apt-get install php5-mcrypt
接著啟動mcrypt模組
sudo php5enmod mcrypt
sudo service apache2 restart
如此,應該不會再有警告訊息!

3.假設想使用https來連接,且將domain name直接連結到Roundcube,請修改/etc/apache2/sites-available/default-ssl.conf檔案,將DocumentRoot的值設定成你的Roundcube資料夾位置,例如
DocumentRoot /var/www/roundcubemail-1.1.3/
接著啟用ssl站台
sudo a2ensite default-ssl
啟用apache2的ssl模組
sudo a2enmod ssl
再重新啟動apapche2
sudo service apache2 restart
接著修改Roundcube資料夾下temp與logs的權限,確定apache2(www-data)有寫入權限
cd /var/www/roundcubemail-1.1.3
sudo chown -R www-data temp logs

4.確定已安裝好Mysql,有需要也可安裝phpmyadmin;新增roundcube所需要的mysql使用者與資料庫,roundcube須對使用的資料庫有寫入權限。

5.用瀏覽器連結至roundcube資料夾下的installer,滿足檢測頁面的要求。如;
https://demodomain/installer



檢測畫面中,資料庫的部分因為我們使用mysql,所以只要mysql的部分有OK就行了,其餘資料庫檢測狀態可以不用理會。若有未安裝的元件,畫面會在元件名稱後顯示NOT AVAILABLE,再將其安裝補齊即可。例如Intl元件未安裝:
sudo apt-get install php5-intl
sudo service apache2 restart
至於date.timezone:  NOT OK(not set)這個訊息,是因為在PHP內沒有設定所在的時區,可以修改/etc/php5/apache2/php.ini檔案:
date.timezone = "Asia/Taipei"
修改完php.ini後需要重新啟動apapche2才會生效!
sudo service apache2 restart
接著應該可以看到如下畫面,點選NEXT到下個步驟。










接下來的畫面分幾個大項
General configuration
support_url 是要連接Roundcube的支援網址
其他可以保留預設值

接著,Database setup部分,
Database type 選擇Mysql
Database server (omit for sqlite) 輸入loclahost
Database name (use absolute path and filename for sqlite) 輸入你在Mysql幫Roundcube開的帳號
Database user name (needs write permissions)(omit for sqlite) 輸入Mysql下Roundcube帳號的密碼

IMAP Settings部分
default_host 輸入IMAP主機,例如ssl://localhost
default_port IMAP主機使用的TCP PORT,例如:993
其他部分可以保留預設值

SMTP Settings
smtp_server SMTP SERVER,若使用加密,請輸入tls://localhost
smtp_port smtp使用的tcp port,預設是25
Use the current IMAP username and password for SMTP authentication 這個選項要勾選,讓smtp使用imap登入的帳號和密碼去驗證

Display settings & user prefs
language 預設的語系,繁體中文可輸入zh_TW

Plugins
選用你想啟動的附加元件
其他選項可以視需求勾選,接著點選CREATE CONFIG












這時應該可以看到如下畫面:







接著,點選CONINUE進入測試畫面。
Check DB config下若看到以下畫面:







請點選Initialize database

Test SMTP config下,


填入一組在SMTP Server上可以寄信的帳號(User)與密碼(Password),Sender填入寄件者的EMAIL,Recipient填入收件者的EMAIL,接著按下Send test mail,若可以正常寄信,會顯示:
SMTP send:  OK

Test IMAP config













填入一組可以登入IMAP的帳號(Username)與密碼(Password),點下Check login,若可以正常登入IMAP,畫面會顯示:
Connecting to ssl://localhost...
IMAP connect:  OK(SORT capability: yes)

到此,Roundcube的設定算是完成了,有發現螢幕下方的那幾列紅字嗎?







為了安全考量,避免未經授權的使用者擅自更改Roundcube的設定,請在你的config.inc.php檔案內加入:
$config['enable_installer'] = false;
確保使用者透過瀏覽器無法讀取installer這個資料夾!

2015年10月13日 星期二

postfix 限制指定帳號只能寄信至指定郵箱

欲限制指定帳號只可寄信至指定郵箱,其餘拒絕,例如希望使用者帳號只在公司內部使用,不可寄信至外部郵箱,可依以下設定。

1.修改postfix的設定檔main.cf

  • 在"smtpd_sender_restrictions ="設定值內加入如下設定:
          check_sender_access hash:/etc/postfix/check_sender
  • 新增限制類別
          smtpd_restriction_classes = local_only
          local_only = check_recipient_access hash:/etc/postfix/local_domains, reject

2.編輯/etc/postfix/check_sender,將要限制的帳號指定到"local_only",帳號須包含網域名稱
           u1@mydomain     local_only

3.編輯/etc/postfix/local_domains,此處指定允許寄件的domain名稱
           mydomain          OK

4.執行postmap產生check_senderlocal_domains的資料檔
postmap check_sender
postmap local_domains

5.重新啟動postfix
service postfix restart

以上!

參考資料:http://www.postfix.org/RESTRICTION_CLASS_README.html