imap

package module
v0.0.0-...-fd76a82 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

README

Examples

Gmail

Google removed plain username+password authentication for 3rd party. You need to create a "App password" to be able to use username+password for authentication.

import Imap from "k6/x/imap";

export default function () {
  const [message, error] = Imap.read(
    "my_email@gmail.com",
    "password123",
    "imap.gmail.com",
    993,
    {
      Subject: ["Verify your email"],
    }
  );

  if (error != "") {
    console.error(error);
  } else {
    console.log(message);
  }
}

emailClient

Use email client if you need to read multiple messages and don't want to login everytime.

import imap from "k6/x/imap";

export default function () {
  const client = imap.emailClient(
    "my_email@gmail.com",
    "password123",
    "imap.gmail.com",
    993
  );

  const loginError = client.login();

  if (loginError != "") {
    console.error(loginError);
    return;
  }

  let [message, err] = client.read({
    Subject: ["Verify your email"],
  });

  if (err != "") {
    console.error(err);
    return;
  }

  console.log(message);
  client.logOut();
}

Build

Don't forget to use this binary instead of the k6 binary in your path.

xk6 build --with github.com/eugercek/xk6-imap

# ./k6 run script.js

TODO List

  • Give examples for major email providers
  • Give examples for how to measure elapsed time
  • Create unit tests for the Go code
  • Expose more query options

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Imap

type Imap struct{}

func (*Imap) EmailClient

func (*Imap) EmailClient(email, password, url string, port int) *ec.EmailClient

Create new email client

func (*Imap) Read

func (*Imap) Read(email, password, URL string, port int, header textproto.MIMEHeader) (string, string)

Simple function for one time read Use EmailClient for more complex needs

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL