Fetch email and extract photos

Programming Snapshot – Go Mail Client

© Lead Image © Tatiana Venkova, 123RF.com

© Lead Image © Tatiana Venkova, 123RF.com

Article from Issue 282/2024

In this month's column, Mike Schilli writes a special mail client in Go and delves into the depths of the IMAP protocol in order to archive photos from incoming emails.

Popular email clients such as Thunderbird or Microsoft Outlook make it very easy to automatically filter and forward incoming messages. I recently had the idea of sending freshly taken photos to my account by email, from where my desktop computer would automatically retrieve them at regular intervals, extract the photos from the email body, and proceed to archive them (Figure 1). How difficult would it be to fetch emails from the provider with a DIY Go program and extract the photos embedded in MIME format in order to store them on my hard disk? Luckily, Go libraries make quick work of such problems!

Transport Logistics

In order for turnkey email clients to gain access to your choice of provider's mail server, they require three parameters: the IMAP server including the port, the username, and the password. Besides this, you are always asked for the SMTP server and port, possibly along with any other credentials you might have there. The reason for this is that two completely different technologies are used to collect and send email, and they usually run on different servers.

Protocols such as IMAP (or maybe POP3) check whether a user on the mail server has mail. To do this, the email client contacts the server and asks how many messages there are. The client can then either download the messages individually and store them in folders or even delete them.


Use Express-Checkout link below to read the full article (PDF).

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Back up Email with a Single Command
  • IMAP Proxies

    IMAP proxies like Perdition, Imapproxy, and Cyrus Aggregator help distribute mail to multiple IMAP servers. We examine some options for IMAP proxy in the Linux evironment.

  • Geary Email Client

    Managing email on an IMAP server is part of everyday business. The slim client Geary makes it as simple on the desktop as it is on many mobile devices – despite a few remaining shortcomings.

  • Perl: IMAP Chat Log

    Are you interested in storing, organizing, and searching instant messaging conversations on your IMAP server? The Perl script in this month’s column can help you do just that.

  • Mutt for Beginners

    Mutt, a command-line email client, can do anything a desktop client can with less overhead and a smaller attack surface. Here's how to get started.

comments powered by Disqus