A simple Go POP3 client library for connecting and reading mails from POP3 servers.

go-pop3

A simple Go POP3 client library for connecting and reading mails from POP3 servers. This is a full rewrite of TheCreeper/go-pop3 with bug fixes and new features.

Install

go get -u github.com/knadh/go-pop3

Example

import (
	"fmt"
	"github.com/knadh/go-pop3"
)

func main() {
	// Initialize the client.
	p := pop3.New(pop3.Opt{
		Host: "pop.gmail.com",
		Port: 995,
		TLSEnabled: true,
	})

	// Create a new connection. POP3 connections are stateful and should end
	// with a Quit() once the opreations are done.
	c, err := p.NewConn()
	if err != nil {
		log.Fatal(err)
	}
	defer c.Quit()

	// Authenticate.
	if err := c.Auth("myuser", "mypassword"); err != nil {
		log.Fatal(err)
	}

	// Print the total number of messages and their size.
	count, size, _ := c.Stat()
	fmt.Println("total messages=", count, "size=", size)

	// Pull the list of all message IDs and their sizes.
	msgs, _ := c.List(0)
	for _, m := range msgs {
		fmt.Println("id=", m.ID, "size=", m.Size)
	}

	// Pull all messages on the server. Message IDs go from 1 to N.
	for id := 1; id <= count; id++ {
		m, _ := c.Retr(id)

		fmt.Println(id, "=", m.Header.Get("subject"))

		// To read the multi-part e-mail bodies, see:
		// https://github.com/emersion/go-message/blob/master/example_test.go#L12
	}

	// Delete all the messages. Server only executes deletions after a successful Quit()
	for id := 1; id <= count; id++ {
		c.Dele(id)
	}
}

PkgGoDev

To-do: tests

Setup a Docker test environment that runs InBucket POP3 + SMTP server to run a dummy POP3 server and test all the commands in the lib.

Licensed under the MIT License.

Owner
Kailash Nadh
Hobbyist developer | CTO @zerodha | Volunteer @fossunited
Kailash Nadh
Similar Resources

aerc is an email client for your terminal.

aerc aerc is an email client for your terminal. This is a fork of the original aerc by Drew DeVault. A short demonstration can be found on https://aer

Dec 14, 2022

📧 Go client for the OhMySMTP email service

go-ohmysmtp A Go wrapper for the OhMySMTP email service. Package https://github.com/jackcoble/go-ohmysmtp Examples Send an email. package main impor

Dec 13, 2021

aerc is an email client for your terminal.

aerc aerc is an email client for your terminal. This is a fork of the original aerc by Drew DeVault. A short demonstration can be found on https://aer

Apr 16, 2022

Robust and flexible email library for Go

email Robust and flexible email library for Go Email for humans The email package is designed to be simple to use, but flexible enough so as not to be

Dec 30, 2022

:envelope: A streaming Go library for the Internet Message Format and mail messages

go-message A Go library for the Internet Message Format. It implements: RFC 5322: Internet Message Format RFC 2045, RFC 2046 and RFC 2047: Multipurpos

Dec 26, 2022

A simple CSS parser and inliner in Go

douceur A simple CSS parser and inliner in Golang. Parser is vaguely inspired by CSS Syntax Module Level 3 and corresponding JS parser. Inliner only p

Dec 12, 2022

a simple api that sent spam via sms and email

a simple api that sent spam via sms and email routes: /sms /email example request with python

Oct 19, 2021

📮 Simple (but useful) email sender written in pure Go v1.17. Support HTML templates and attachments.

📮 Go Email Sender Simple (but useful) email sender written in pure Go v1.17. Yes, yet another email package here! 😅 Support HTML templates and attac

Dec 31, 2021

A simple microservice designed in Go using Echo Microframework for sending emails and/or calendar invitations to users.

Calenvite A simple microservice designed in GO using Echo Microframework for sending emails and/or calendar invitations to users. Features Send emails

Oct 29, 2022
Comments
  • Ignoring large attachments

    Ignoring large attachments

    I can get the message size through List() method. But is there a way to retrieve the message but only text part, ignoring attachments(in case they are too big)?

  • Handle `+OK` and `-ERR` without additional info

    Handle `+OK` and `-ERR` without additional info

    • Handle +OK and -ERR responses without additional info (global vars: respOK, respErr).
    • Move bOK inside parseResp() to global var and renamed to respOKInfo.
    • Move bERR inside parseResp() to global var and renamed to respErrInfo.
    • Include actual response in error message.

    Notes:

    • Dovecot returns +OK if authentication succeeds.
    • According to RFC 1081, it's possible server returns +OK and -ERR without additional info. https://datatracker.ietf.org/doc/html/rfc1081
A simple parser for the query used in gmail to filter for e-mails

Go Gmail Query Parser by Dustin Breuer This project is work in progress. Prerequisites Before installing this project you need: ?? Go (at least 1.17)

Feb 2, 2022
Golang package that generates clean, responsive HTML e-mails for sending transactional mail
Golang package that generates clean, responsive HTML e-mails for sending transactional mail

Hermes Hermes is the Go port of the great mailgen engine for Node.js. Check their work, it's awesome! It's a package that generates clean, responsive

Dec 28, 2022
This command line tool exports .eml files from POP3 account.

export-mail This command line tool exports .eml files from POP3 account. Install > go get github.com/gonejack/export-mail Usage > export-mail --host i

Dec 6, 2021
go-pst is a library for reading PST files (written in Go/Golang).
go-pst is a library for reading PST files (written in Go/Golang).

go-pst A library for reading PST files (written in Go/Golang). Introduction go-pst is a library for reading PST files (written in Go/Golang). The PFF

Dec 29, 2022
:inbox_tray: An IMAP library for clients and servers

go-imap An IMAP4rev1 library written in Go. It can be used to build a client and/or a server. Usage Client package main import ( "log" "github.com

Jan 6, 2023
Monitoring and automation for Open Source email servers, starting with Postfix.
Monitoring and automation for Open Source email servers, starting with Postfix.

Welcome to Lightmeter Control Center, the Open Source mailops monitoring application.

Dec 19, 2022
Filtering spam in mail server, protecting both client privacy and server algorithm

HE Spamfilter SNUCSE 2021 "Intelligent Computing System Design Project" Hyesun Kwak Myeonghwan Ahn Dongwon Lee abstract Naïve Bayesian spam filtering

Mar 23, 2022
Lightweight SMTP client written in Go

Hectane Hectane is both a Go package providing an SMTP queue for sending emails and a standalone application that exposes this functionality via an HT

Nov 23, 2022
IMAP4rev1 Client for Go

IMAP4rev1 Client for Go ======================= To download and install this package run: go get github.com/mxk/go-imap/imap The documentation is a

Nov 20, 2022
POP-3 client package for Go.

GOP-3 (Go + POP-3) is a POP-3 client for Go. It has experimental purpose and it is still under development. RFC 1939 document has been followed while developing package.

Dec 25, 2021