上个星期的工作任务是为Ipcamera程序添加个邮件发送功能。一番苦寻,找到esmtp来作为邮件的发送代理MTA,关于smtp,原作者是这么说的:
Since the moment I switched to Linux I had some problems to have email properly configured to my personal needs. I use a POP3/SMTP mail account for my personal mail, and I usually connect to the internet with my laptop via several LANs (home, work, ...) with several different firewall configurations. The standard MTAs didn't provided the flexibility I needed -- they either failed to deliver the mail directly or failed to authenticate with the relay, or were configured system-wide and conflicted with the local MTA.
fetchmail always worked fine to get email, but I needed a sendmail alike program to send email from Mutt. Basically I wanted a program which could be for SMTP what fetchmail was for POP3, i.e., an user configurable MTA with authorization support.
Some small modifications to the mail-file example from libESMTP did the trick. After receiving positive feedback from the libESMTP author, Brian Stafford, I decided to make the program more comfortable for others to use -- adding a command-line option parser extracted from sendmail, a configuration file parser from fetchmail, a man page based on ssmtp and sendmail man pages and using the autotools to wrap it all up. The result of this cut and paste effort was esmtp. Well, the first version, that is. Since then a few more bells and whistles were added, with the help of some contributors.
一句话说,就是作者用着Linux常用的邮件服务程序不爽,就自己写一个 ~~!
esmtp的安装的具体信息和过程如下描述:
The lightweight eSMTP allows per-user configuration files, making it useful even for multi-user systems.
Most Linux distributions install programs like Sendmail or Postfix to handle local mail deliveries.
While this works fine on multi-user systems or servers, these programs are quite large and complex for single-user desktop systems.
For Linux machines with a single user, the use of more lightweight mail "servers" may be desired--programs like sSMTP or eSMTP. eSMTP allows per-user configuration files unlike other similar programs, and so it's useful even for multi-user systems.
eSMTP is packaged in some distributions so it may be easily installed using urpmi, apt, or yum. If not, it is trivial to install although it does require the libESMTP library.
If your chosen Linux distribution does not provide a binary copy of eSMTP, download the latest version of libESMTP (1.0.4) and eSMTP (0.6.0) and compile and install them using:
$ tar xvjf libesmtp-1.0.4.tar.bz2
$ cd libesmtp-1.0.4
$ ./configure --prefix=/usr/local
$ make
$ sudo make install
$ cd ..
$ tar xvjf esmtp-0.6.0.tar.bz2
$ cd esmtp-0.6.0
$ ./configure --prefix=/usr/local --with-libesmtp=/usr/local
$ make
$ sudo make install
The resulting libESMTP libraries will be installed in /usr/local, as will the esmtp program. Configuration for esmtp is done via the ~/.esmtprc file.
The ~/.esmtprc configuration file is very straightforward. A very basic one may look like:
hostname = mail.server.com:25
username = "joe"
password = "secret"
starttls = enabled
mda "/usr/bin/procmail -d %T"
This defines the server to which to send mail (the mail hub) — mail.server.com on port 25 with the username "joe" and the password "secret". It also enables the STARTTLS extension. Finally, it defines the local mail delivery agent, procmail.
If you use multiple accounts, you can also tell eSMTP to use multiple SMTP servers dependent upon which account you are sending mail from by using the "identity" keyword:
identity joe@mail.com
hostname mail.server.com:25
username "joe"
password "secret"
starttls enabled
default
identity joe@gmail.com
hostname smtp.gmail.com:587
username "joe@gmail.com"
password "secret2"
starttls required
mda "/usr/bin/procmail -d %T"
eSMTP determines which server to use with the envelope sender flag, which is the -f option to Sendmail and similar MTA's. For mail clients such as Mutt, this can be set with the set envelope_from=yes configuration option. Likewise, the path to Sendmail should be defined as /usr/local/bin/esmtp.
For other mail clients, simply telling them to use the local Sendmail and pointing the path to /usr/local/bin/esmtp should be sufficient. If you're unable to define the path to Sendmail, you can also opt to change /usr/lib/sendmail to a symlink pointing to /usr/local/bin/esmtp.
Finally, eSMTP can use the STARTTLS extension, but in order for it to do so, you need to add the root certificate of the CA that signed the server's SSL certificate.
eSMTP looks for this information in the ~/.authenticate/ directory. For simplicity, simply download the Mozilla bundle of CA root certificates into this directory; an appropriate bundle suitable for eSMTP can be obtained from the cURL Web site.
$ mkdir ~/.authenticate
$ chmod 0700 ~/.authenticate
$ curl http://curl.haxx.se/ca/cacert.pem >~/.authenticate/ca.pem
$ chmod 0600 ~/.authenticate/ca.pem
With all of this complete, you can use eSMTP to relay mail to an upstream provider SMTP service with ease, without worrying about configuring local Sendmail or Postfix services, which can be especially useful for mail clients with limited or no support for remote SMTP servers.
esmtp及其开发包可在大部分Linux系统上编译安装,并正常运行---应该是如此吧,至少在DM355+MontaVista Linux能够实现。