Back

在Debian/Ubuntu Server中使用Gmail

|

搭建一个邮件服务器是一件很简单的事情,但是发出的邮件绝大部分会被分拣到垃圾箱里面去,这个时候可以用Gmail的SMTP搭建一个轻量可用的邮件服务。

1. 安装必要的软件:
[cc lang="bash"]sudo apt-get install exim4 mailutils[/cc]
如果你需要在cli环境下撰写邮件,还可以加装一个mutt. mailutils是一个GNU邮件套装,例如mail命令就包含其中。
2. 配置exim:
[cc lang="bash"]sudo dpkg-reconfigure exim4-config[/cc]
这条命令会弹出一个配置向导,我选择:
* Server Type: **Sent by smarthost, received Via SMTP.**
* System Mail Name: **输入你的FQDN主机名,例如 bird.skylast.com.**
* IP-addresses to listen on: **保持默认值**
* Other destinations: **FQDN主机名,例如 bird.skylast.com**
* Machines to relay mail for: **留空或保持默认**
* IP address or host name of the outgoing smarthost: **smtp.gmail.com::587**剩下几项保持默认值,直接回车即可。
最后编辑**/etc/exim4/passwd.client**文件,按照下面的格式增加一条:
[cc lang="bash"]\*.google.com:[email protected]:GmailPassword
\*.gmail.com:[email protected]:GmailPassword[/cc]
替换其中的邮件地址和邮件密码为正确值,保存并修改权限:
[cc lang="bash"]
chown root:Debian-exim /etc/exim4/passwd.client
chmod 640 /etc/exim4/passwd.client #不然系统上的其他用户可以看到你的gmail密码
[/cc]
3. 测试:
[cc lang="bash"]echo "Some text here"|mail -s "Subject" [email protected][/cc]
如果能收到邮件,说明配置成功;如果没有收到 ,可以查看一下**/var/log/exim4/mainlog**的日志记录。
4. 可选设置:
编辑文件:**/etc/aliases** ,添加几行:
[cc lang="bash"]
root: email-address
username: email-address
[/cc]
这样exim4会把发送给root或者username的系统邮件(通常是错误报告)转发到指定的邮箱里面。另外编辑**php.ini**文件,添加一行:
[cc lang="bash"]sendmail\_path = /usr/sbin/sendmail -t -i[/cc]
这样php也可以使用gmail发送邮件了。

No comments yet

Leave a comment

About me

I live in Tasmania, an island a little far from the rest of the world and very close to the sea.
Father of two little girls, have two puppies.

Work

Work in IT industry, AI is my working partner.