今天即兴之下弄了六个多小时的linux,主要配置了终端下的邮件服务器配置。
这里用到了mutt+msmtp+fetchmail,另外我用c++写了一个直接获取附件的小程序。虽然看起来不美,但怎么说也是自己的劳动成果 : )
为了节省流量和加快速度,我直接用学校的邮箱.
首先是mutt的配置文件( ~/.muttrc )
#################################################
#忽略文件头
ignore *
unignore From: To: Cc: Subject: Date: #Only these are shown in the header
#下面是在邮件头显示的名字
set realname='suikay'
set sendmail="/usr/bin/msmtp"
#下面设置了vim作为编辑器
set editor=vim
set envelope_from=yes
set use_from=yes
################################################
下面是msmtp的配置文件(~/.msmtprc)
大写的是要改的
#默认的系统用户(同上)
account SYSTEM_USER_NAME
host smtp.cqu.edu.cn
#protocol smtp
auth login
#显示于邮件的邮箱名
from YOURNAME@SMTP.ISP.COM
#账户
user YOUR_EMAIL_ACCOUNT
#密码
password YOUR_PASSWORD
#默认的系统用户(同上)
account default: SYSTEM_USER_NAME
################################
fetchmail 的配置文件 (~/.fetchmailrc)
同样,大写都是要改的
set daemon 60
poll POP_SERVER(如pop3.mail.com) with proto PROTORL(如pop3)
user 'ACCOUNT' there with password 'PASSWORD' is 'SYSTEM_USER' here
配置好以后就可以用mutt来收发邮件了,或者可以用echo "你的邮件内容" | mutt -s "主题" -a "你要发的附件" "邮件的目的地" 如
echo "This picture is nice.Do you think so ??" | mutt -s "Nice Picture" -a "Beautiful.jpg"suikay@live.cn
另外我写了一个直接从系统的邮件文件(不懂怎么说-_-!)里将附件直接截出来的C++程序。对于Base64的文件不支持,但是可以再加两行代码来实现,在linux下可以用 base64 -d the_ori_file >> the_out_file 将其还原为原来的格式(经过md5测试)。
下面是将附件提取出来的代码,提取出来的文件直接保存于当前目录:
- /*++
- 在邮件文件里面个附件都用如"--asdfASDJF/asdf---"的一段十几个乱字符分隔.
- 而且附件如果是Base64格式则会被转化为ascii文件(这个程序只是将ascii提取
- 出来而没有将其还原.
- */
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- int main()
- {
- string boundary,content,name;
- ifstream in("/var/spool/mail/suikay");
- ofstream out;
- //找到边界
- while(getline(in,content)&& content.find("boundary=")==string::npos);
- //如果没有找到边界退出 (如果没有这句代码会导致错误)
- if(!content.size())
- return 0;
- // 将边界提取出来
- boundary = content.substr(content.find("boundary=")+10,16);
- for(int i = 0;i < 7;i++)
- getline(in,content);
- while(getline(in,content) && content.find(boundary) == string::npos)
- cout << content;
- while(getline(in,content)) {
- while(getline(in,content) && content.find("filename") == string::npos);
- name = content.substr(content.find("/"")+1);
- name.resize(name.size() - 1);
- cout << name;
- //将新的附件文件打开以进行写入
- out.open(name.c_str());
- getline(in,content);
- getline(in,content);
- getline(in,content);
- out << content;
- while(getline(in,content)&&content.find(boundary)==string::npos)
- out << endl << content;
- out.close();
- }
- in.close();
- return 0;
- }
技术不高再加时间紧迫,肯定有不少bug,如有发现请不吝指教。
来自:http://blog.csdn.net/suikay/article/details/3680639