spa*_*cle 4 php python mysql email bash
我需要对从Gmail收到的电子邮件运行查询.当我运行Google Business Apps时,我有POP和IMAP访问权限.为了避免使用API,我只想将电子邮件下载到MySQL数据库.最后,我将展示CRM的使用情况统计数据和指标,但现在我只需要定期下载(每5分钟一次).
附加信息:我使用的是Ubuntu 14.04.我的应用程序将使用PHP构建,但为了简单起见,我可以使用bash或Python脚本获取所有电子邮件.我此刻并不挑剔.
我遇到过一些非常过时的PHP脚本,但我想知道是否还有更新的东西:
http://www.phpclasses.org/package/3324-PHP-Retrieve-e-mail-messages-into-a-MySQL-database.html http://www.phpclasses.org/package/2-PHP-Access -to-电子邮件的邮箱,使用最POP3-protocol.html
PS我打算使用像WebMail Lite或Roundcube这样的开源电子邮件客户端,但他们似乎并没有将电子邮件保存到数据库中,但我认为他们可能实际上使用的API可能允许我获取统计数据需要但又一次,我认为会有一个更有效的解决方案.
对于这么简单的事情,你不需要一个完整的库.
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'myemail@gmail.com';
$password = 'mypassword';
$inbox = imap_open($hostname,$username,$password);
$emails = imap_search($inbox,'ALL');
foreach($emails as $e){
$overview = imap_fetch_overview($inbox,$e,0);
$message = imap_fetchbody($inbox,$e,2);
// the body of the message is in $message
$details = $overview[0];
// you can do a var_dump($details) to see which parts you need
//then do whatever to insert them into your DB
}
Run Code Online (Sandbox Code Playgroud)