Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
8
rated 0 times [  8] [ 0]  / answers: 1 / hits: 30079  / 2 Years ago, mon, september 26, 2022, 8:57:21

I know I can download emails using a client, but is there a way to download emails straight from the terminal? I'm trying to fetch some emails from my gmail to later do some analysis on certain emails.



EDIT: Thank you for all the answers. Right now, I found a way to do it with getmail. But I encountered a small issue. It downloads the emails and attachments, but it prints everything in text. Is there a way to actually retrieve said attachment?


More From » downloads

 Answers
5

Gmail provides an IMAP service through which you can use any client that supports that protocol to fetch your e-mails. How that client makes them available on the disk can vary.



By far the most widely-used command-line IMAP client has to be fetchmail. You can install it easily in Ubuntu, then google for specific configurations to use with gmail.



One thing with fetchmail is that it slurps emails from the remote server and then pipes them through your local MTA. So you'd need to have a locally-configured MTA for this setup to work. The MTA would presumably then append the emails to /var/mail/$USER, and you can then read this file to do your processing.



Another tool that may work is offlineimap. I haven't used it; setup may be easier than with fetchmail.



As for your need to save attachments included in emails, what you need is to install mpack. Then, run the munpack command on the .txt file for each email (yes, the one that contains all the gibberish from the attachments). It will decode and save the attachments in individual files:



$ munpack mail.txt 
Invoice.PDF (application/pdf)
my-picture.png (image/png)

[#36549] Monday, September 26, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
measord

Total Points: 259
Total Questions: 131
Total Answers: 106

Location: Venezuela
Member since Sun, Oct 2, 2022
2 Years ago
measord questions
Wed, Jul 14, 21, 21:39, 3 Years ago
Mon, May 16, 22, 21:12, 2 Years ago
Mon, Oct 11, 21, 03:11, 3 Years ago
Sun, Apr 17, 22, 21:22, 2 Years ago
;