Email tracking pixels

See if emails are opened by sending tracking pixels. Receive open events via Webhook or view which recipients opened an email in the MailSlurp dashboard

email open track event

See if emails are opened by sending tracking pixels. Receive open events via Webhook or view which recipients opened an email in the MailSlurp dashboard.

Code example

import 'jest';
import fetch from "node-fetch"
import { MailSlurp } from 'mailslurp-client';

const timeout = 120000
const mailslurp = new MailSlurp({ apiKey: process.env.apiKey });
jest.setTimeout(timeout);


describe('tracking controller', () => {
    it('can create a pixel and trigger seen', async () => {
        const pixel = await mailslurp.trackingController.createTrackingPixel({})
        expect(pixel.seen).toEqual(false)
        const res = await fetch(pixel.url)
        expect(res.ok).toBeTruthy()
        const pixel2 = await mailslurp.trackingController.getTrackingPixel(pixel.id)
        expect(pixel2.seen).toEqual(true)
    })
    it('can send email with tracking', async () =>{
        const inbox1 = await mailslurp.createInbox()
        const inbox2 = await mailslurp.createInbox()
        const sent = await mailslurp.inboxController.sendEmailAndConfirm(inbox1.id!, {
            to: [inbox2.emailAddress!],
            body: "<html><body>Hello user</body></html>",
            addTrackingPixel: true
        })
        expect(sent.pixelIds?.length).toEqual(1)
        const pixelId = sent.pixelIds?.[0]
        const pixel = await mailslurp.trackingController.getTrackingPixel(pixelId!)
        expect(pixel.seen).toEqual(false)
        const res = await fetch(pixel.url)
        expect(res.ok).toBeTruthy()
        const pixel2 = await mailslurp.trackingController.getTrackingPixel(pixel.id)
        expect(pixel2.seen).toEqual(true)
    })
});

Ready to dive in?Start building email applications today.