Howto: receive mail and save attachment with fetchmail, procmail and metamail
来源:互联网 发布:mac 10.12 dns flush 编辑:程序博客网 时间:2024/06/06 04:26
At work I recently had to set up a solution that periodically checks a POP3 account on our M$ Exchange wannabe mailserver, and saves the attachments to some folder for further processing. As I didn't find a ready-to-go-solution for this on the web, just snippets here and there, and of course hundrets of other people asking the same, here it is.
You will need
- fetchmail
- procmail
- metamail (or uudeview, see first comment below)
In this example I'll use a POP3 account, the full mail will be backed up to ~/mail_backup, and attachments will be unpacked to ~/attachments. fetchmail also handles IMAP accounts just fine. Please refer to the fetchmail documentation.
Setting up fetchmail
First create a file $HOME/.fetchmailrc
poll my.pop3.server protocol pop3 user 'myuser' password 'mypassword' mda '/usr/bin/procmail -d %T'
Setting up procmail and metamail
Then we configure procmail so it forwards the messages to metamail in $HOME/.procmailrc
:0*^content-Type:{ # backup the complete mail first.. # you can leave out this part if you don't want a backup of the complete mail :0c: $HOME/mail_backup # Now the actual unpacking part # # this is the place where the attachments will be unpacked to METAMAIL_TMPDIR=$HOME/attachments # forward to metamail :0fw | metamail -w -y -x}
Regarding metamail, we tell it to ignore any mailcap file, so it doesn't use interpreters (-w), yanking the message and save the content raw (-y) and force it in non-interactive mode (-x).
That's it about it. We are ready for testing.
Test run
Now we simply fire up fetchmail, the rest should be magic.
fetchmail -kv
- Howto: receive mail and save attachment with fetchmail, procmail and metamail
- Fetchmail and mutt
- Configuring Fetchmail, Exim4 and Mutt
- HOWTO Apache2 with subversion SVN and DAV
- 从零开始配置mutt-fetchmail-procmail-msmtp
- 从零开始配置mutt-fetchmail-procmail-msmtp
- mutt+fetchmail+procmail+exim4 邮件服务器
- Generate PDF from Batch Class and schedule class and send email notification with Pdf attachment
- Procmail 过滤mail病毒
- Howto base64 encode with C/C++ and OpenSSL
- UART Receive FIFO and Receive Timeout
- UBIFS FAQ and HOWTO
- Plug-and-Play-HOWTO
- UBI FAQ and HOWTO
- UBIFS FAQ and HOWTO
- UBIFS FAQ and HOWTO
- UBI FAQ and HOWTO
- Struts 2 File Upload and Save Tutorial with Example
- 项目计划管理软件:GanttProject
- vim 命令
- 改善C++代码的学习笔记2
- Shanghai ** Product Development Plan
- 我的yum配置
- Howto: receive mail and save attachment with fetchmail, procmail and metamail
- 浅谈inline HOOk之ring0下的进程保护
- Linux程序的安装
- 如何有效防止PHP木马对linux操作系统提权
- 整理我的264的模糊概念——请教小徐老师的心得
- 图片格式的PHP验证码的实现
- uimsbf和 bslbf的含义
- Dart 比 JavaScript 更酷的10个理由
- Shanghai ** Product Development Plan