简体   繁体   English

使用 fetchmail 一次性从 gmail 中提取电子邮件

[英]Using fetchmail for one time email extraction from gmail

  • I'm trying to use fetchmail in terminal to extract e-mails from my gmail account.我正在尝试在终端中使用fetchmail从我的 gmail 帐户中提取电子邮件。
  • I configured my ~/.fetchmailrc with:我配置了我的~/.fetchmailrc
poll imap.gmail.com protocol POP3
   user "someuser@gmail.com" is oren here
   password 'verysecretpassword'

(Of course with real username+password). (当然使用真实的用户名+密码)。

  • Then I tried to naively extract emails with: $ fetchmail .然后我尝试天真地提取电子邮件: $ fetchmail
  • Sadly nothing happened, and all I got was:可悲的是什么也没发生,我得到的只是:
fetchmail: 6.3.26 querying imap.gmail.com (protocol POP3) at Mon 03 Feb 2020 14:34:46 IST: poll started
Trying to connect to <ADDRESS> ... connection failed.

Using Fetchmail使用 Fetchmail

It looks like the config is set to poll an IMAP server but then specifying POP3 protocol.看起来配置设置为轮询 IMAP 服务器,然后指定 POP3 协议。 Try something like this for the ~/.fetchmailrc file:~/.fetchmailrc文件尝试类似的操作:

set postmaster "local_user"
set daemon 600
poll pop.gmail.com with proto POP3
   user 'gmail_user_name' there with password 'app_password' is local_user here options ssl fetchlimit 400

where:在哪里:

  • local_user is some local account where undeliverable mail should go (the "last ditch effort" before failing permanently). local_user是一些无法投递的邮件应该去的本地帐户(永久失败之前的“最后努力”)。
  • gmail_user_name is everything to the left of the @ in the email address. gmail_user_name是电子邮件地址中@左侧的所有内容。
  • app_password is a specially generated password that is restricted to the gmail application (go here: https://myaccount.google.com/ and click Security , then app passwords and generate a new app password) app_password是一个专门生成的密码,仅限于 Gmail 应用程序(转到此处: https : app_password并点击Security ,然后点击app passwords并生成新的应用密码)

What to do at this point will depend on your local setup.此时要做什么取决于您的本地设置。 Fetchmail will... fetch mail (clearly).... and then deliver it to the local machine's delivery system. Fetchmail 将...获取邮件(显然)...然后将其发送到本地机器的发送系统。 If you have sendmail (a pretty safe bet), this might work:如果您有 sendmail(一个非常安全的赌注),这可能有效:

$ fetchmail -d0 -avNk -m "/usr/sbin/sendmail -i -f %F -- %T" pop.gmail.com

Mail should start flowing in. Messages can be read using the mail command or get the raw content from /var/mail/[username] .邮件应该开始流入。可以使用mail命令读取mail或从/var/mail/[username]获取原始内容。 This might not get everything in one shot;这可能无法一蹴而就; it very likely won't if the address has accumulated even a small amount of history.如果地址积累了少量历史记录,则很可能不会。 Let it finish and check that it worked as expected.让它完成并检查它是否按预期工作。 If everything looks good, then it's time to start fetchmail as a daemon process and let it download the entire mailbox.如果一切看起来都不错,那么是时候将fetchmail作为守护进程启动并让它下载整个邮箱。 First, configure fetchmail with appropriate polling interval and batch size settings 1 .首先,使用适当的轮询间隔和批量大小设置1配置fetchmail

  • Confirm that the polling interval is configured in the ~/.fetchmailrc by the line daemon 600 (ie. 10 minute polling interval).确认在~/.fetchmailrc由 line daemon 600配置了轮询间隔(即 10 分钟轮询间隔)。
  • Confirm that the polling option fetchlimit 400 is set in the ~/.fetchmailrc under the options section in the poll pop.gmail.com stanza.确认在poll pop.gmail.com节的options部分下的~/.fetchmailrc设置了轮询选项fetchlimit 400 This is the maximum number of messages to fetch per poll.这是每次轮询要获取的最大消息数。
  • Start fetchmail using the same command as above, but omit the -d0 switch .使用与上述相同的命令启动 fetchmail,但省略-d0开关

Fetchmail should start as a true daemon and continue to periodically download batches of messages until the whole mailbox is downloaded. Fetchmail 应该作为一个真正的守护进程启动,并继续定期下载批量邮件,直到下载整个邮箱。 You will need to remember to kill the daemon process if you don't want it to continue syncing until the next reboot.如果您不希望它在下次重新启动之前继续同步,则需要记住终止守护进程。




Using Google Takeout使用 Google 外卖

You can do this super easy using Google Takeout .您可以使用Google Takeout轻松完成此操作。 Log in, click the "deselect" option at the top of the list, then scroll down to Mail and check just that.登录,单击列表顶部的“取消选择”选项,然后向下滚动到“ Mail并进行检查。 You can choose to get the data in a .zip or .tgz file.您可以选择以.zip.tgz文件的形式获取数据。 They will send you an email when the archive is ready for download.当存档可供下载时,他们会向您发送电子邮件。 It is packaged in an mbox file but that is pretty straightforward to convert to other formats.它打包在一个mbox文件中,但转换为其他格式非常简单。

This is probably the easiest way to accomplish a one time export, and I think they have an option to set up a recurring export too.这可能是完成一次性导出的最简单方法,我认为他们也可以选择设置重复导出。 It probably isn't offering as much control compared to using the developer API directly, but it's a lot less hassle.与直接使用开发人员 API 相比,它可能没有提供那么多的控制,但它的麻烦要少得多。




1: I believe Google has some rate limiting in place, so I am adding some steps to accommodate those limits. 1:我相信谷歌有一些速率限制,所以我添加了一些步骤来适应这些限制。 These are conservative values, since I don't know exactly what the limits are (or even for sure if they exist).这些是保守值,因为我不确切知道限制是什么(甚至不确定它们是否存在)。 If you know more, or care to research it, adjust these values to whatever you think is best.如果您了解更多信息,或想对其进行研究,请将这些值调整为您认为最好的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM