fetchmail是一个Linux系统下全功能的 IMAP 和 POP 客户端程序,它允许用户自动地从远程的 IMAP 和 POP 服务器上下载邮件,并保存到本地客户机转发给客户机上的邮件软件,类似于multipop功能;当然他的功能不只如此。
今天我们用到的是fetchmail配合time命令实现邮件下载耗时统计;通俗的说就是从邮件服务器上通过POP协议收取一定量的邮件,最后统计收取这些邮件所花费的时间,再根据总收取邮件的大小,时间,来计算出邮件服务器的带宽速度。此功能通长应用于从各个地方/国家分布的点来测试连同一台邮件服务器的速度,以便对邮件服务器的带宽改善等做出一个正确的判断。
1、安装fetchmail
我这边是CentOS系统,其实可以yum安装fetchmail,但是yum安装的版本太低,有很多bug,所以我们不建议yum安装,而是从官网下载最新源码包进行编译安装,目前最新版为6.3.26,官网:http://www.fetchmail.info
下载源码安装包(1.3M左右):
[root@localhost /]# wget --no-check-certificate https://ncu.dl.sourceforge.net/project/fetchmail/branch_6.3/fetchmail-6.3.26.tar.xz
解压缩:
[root@localhost /]# tar xpvf fetchmail-6.3.26.tar.xz
如在解压缩中遇到tar (child): xz: Cannot exec: No such file or directory错误,请安装xz软件包:
[root@localhost /]# yum install xz -y
编译安装:
[root@localhost /]# cd fetchmail-6.3.26
[root@localhost fetchmail-6.3.26]# ./configure --prefix=/usr
[root@localhost fetchmail-6.3.26]# make
[root@localhost fetchmail-6.3.26]# make install
等待编译安装完成,查看到已安装成功,fetchmail版本为6.3.26:
[root@localhost /]# fetchmail -V
fetchmail: WARNING: Running as root is discouraged.
This is fetchmail release 6.3.26+NLS.
Copyright (C) 2002, 2003 Eric S. Raymond
Copyright (C) 2004 Matthias Andree, Eric S. Raymond,
Robert M. Funk, Graham Wilson
Copyright (C) 2005 - 2012 Sunil Shetye
Copyright (C) 2005 - 2013 Matthias Andree
Fetchmail comes with ABSOLUTELY NO WARRANTY. This is free software, and you
are welcome to redistribute it under certain conditions. For details,
please see the file COPYING in the source or documentation directory.
Fallback MDA: (none)
Linux localhost.localdomain 2.6.32-642.el6.x86_64 #1 SMP Tue May 10 17:27:01 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
Taking options from command line
No mailservers set up -- perhaps /root/.fetchmailrc is missing?
2、统计POP收取邮件服务器邮件所用时间
例如用time+fetchmail命令收取215.14.64.54邮件服务器上hmj@testemail.com用户邮箱的邮件,执行命令后需要手动输入一下邮箱的密码。
[root@localhost tmp]# time fetchmail --bsmtp testemail -B 100 -p pop3 -u hmj@testemail.com -a -k 215.14.64.54
fetchmail: WARNING: Running as root is discouraged.
Enter password for hmj@testemail.com@215.14.64.54:
3 messages for hmj@testemail.com at 215.14.64.54 (33946083 octets).
reading message hmj@testemail.com@215.14.64.54:1 of 3 (7393530 octets) not flushed
reading message hmj@testemail.com@215.14.64.54:2 of 3 (1451 octets) not flushed
reading message hmj@testemail.com@215.14.64.54:3 of 3 (26551102 octets) not flushed
real 1m15.249s
user 0m0.315s
sys 0m5.746s
结果可以看到,总共下载了3封邮件,总大小为33946083B(约为33946KB,33.9MB),耗时1m15.249s(约75秒)
在此地到邮件服务器的下载带宽速度为:33946KB / 75s = 452KB/s
命令中各参数说明:
--bsmtp testemail 把收取的邮件保存为bsmtp文件,文件名为testemail
-B 100 一次下载100封邮件(此例中其实没必要用此参数,因为此邮箱收件箱总共就3封邮件)
-p pop3 用POP3协议下载邮件
-u hmj@testemail.com 邮件服务器上的邮箱用户名
-a 下载所有已下载过的邮件(以免重复邮件,如多次执行此命令,之前下载的就不会再下载,加上此参数则会再次下载)
-k 下载后在服务器上保留邮件副本
215.14.64.54 邮件服务器地址
原文链接:Linux下用fetchmail程序测试邮件服务器的下载速度,转载请注明来源!
菜鸟的我看了很适应,谢谢!
好几年没用过博客了,支持下!
最近在看有什么邮件群发的软件,不知道是否友这样的软件。。