将POP(Gmail)电子邮件保存到MySQL数据库的最有效方法

2024-10-01 17:26:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要对从Gmail收到的电子邮件进行查询。我有POP和IMAP访问它,因为我正在运行谷歌商业应用程序。为了避免API的使用,我只想将电子邮件下载到MySQL数据库中。最后,我将展示CRM的使用情况统计和指标,但现在我只需要定期下载(每5分钟一次)。在

附加信息:我正在使用ubuntu14.04。我的应用程序将用PHP构建,但为了简单起见,我可以用bash或Python脚本捕捉所有电子邮件。我现在不挑剔。在

我遇到了一些非常过时的PHP脚本,但我想知道是否有更为更新的内容:

http://www.phpclasses.org/package/3324-PHP-Retrieve-e-mail-messages-into-a-MySQL-database.htmlhttp://www.phpclasses.org/package/2-PHP-Access-to-e-mail-mailboxes-using-the-POP3-protocol.html

另外,我本来打算使用像WebMail Lite或Roundcube这样的开源电子邮件客户端,但他们似乎并没有将电子邮件保存到数据库中,尽管我认为他们实际上可能会使用一个API,它可以让我获得所需的统计数据,但我还是认为会有一个更有效的解决方案。在


Tags: org脚本api数据库应用程序httppackage电子邮件
1条回答
网友
1楼 · 发布于 2024-10-01 17:26:32

这么简单的东西你不需要一个完整的图书馆。在

$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
}

相关问题 更多 >

    热门问题