imap

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: Apache-2.0 Imports: 11 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(
    "[email protected]",
    "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(
    "[email protected]",
    "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 ModuleInstance

type ModuleInstance struct {
	// contains filtered or unexported fields
}

ModuleInstance represents an instance of the JS module.

func (*ModuleInstance) EmailClient

func (mi *ModuleInstance) EmailClient(call sobek.ConstructorCall) *sobek.Object

EmailClient is the JS constructor for the email client. It accepts email, password, url, and port as arguments. Usage: const client = new Imap.Client(email, password, url, port);

func (*ModuleInstance) Exports

func (mi *ModuleInstance) Exports() modules.Exports

Exports implements the modules.Instance interface and returns the exports of the JS module. Creiamo esplicitamente un oggetto default che contiene Client come proprietà Questo permette "import Imap from 'k6/x/imap'" e poi "new Imap.Client(...)"

func (*ModuleInstance) Read

func (mi *ModuleInstance) Read(email, password, URL string, port int, headerObj map[string]interface{}) (string, string)

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

type RootModule

type RootModule struct{}

RootModule is the global module instance that will create ModuleInstance instances for each VU.

func New

func New() *RootModule

New returns a pointer to a new RootModule instance

func (*RootModule) NewModuleInstance

func (*RootModule) NewModuleInstance(vu modules.VU) modules.Instance

NewModuleInstance implements the modules.Module interface and returns a new instance for each VU.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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