当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript smtp-server.SMTPServer类代码示例

本文整理汇总了TypeScript中smtp-server.SMTPServer的典型用法代码示例。如果您正苦于以下问题:TypeScript SMTPServer类的具体用法?TypeScript SMTPServer怎么用?TypeScript SMTPServer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SMTPServer类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: SMTPServerConnectTest

function SMTPServerConnectTest() {
    let options: SMTPServerOptions = {
        secure: false,
    };
    let server = new SMTPServer(options);
    server.listen(2323);
}
开发者ID:ArtemZag,项目名称:DefinitelyTyped,代码行数:7,代码来源:smtp-server-tests.ts

示例2: SMTPServerConnectTest

function SMTPServerConnectTest() {
    let options: SMTPServerOptions = {
        secure: false,
    };
    let server = new SMTPServer(options);
    server.on('error', err => {
        console.log('Error %s', err.message);
    });
    server.listen(2323);
}
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:10,代码来源:smtp-server-tests.ts

示例3: callback

    stream.on('data', (chunk: Buffer) => {
        console.log(`[${session.id}] onData got data chunk ${chunk.length} bytes`);
        messageLength += chunk.length;
    });

    stream.once('end', () => {
        console.log(`[${session.id}] onData finished after reading ${messageLength} bytes`);
        callback();
    });
}

function onClose(session: SMTPServerSession) {
    console.log(`[${session.id}] onClose`);
}

const server = new SMTPServer(options);

server.on('error', (err) => {
    console.log(`Server got error:`, err);
});

server.on('close', () => {
    console.log('Server closed');
});

server.listen(port, () => {
    const address = server.server.address();
    console.log(`Listening on [${address.address}]:${address.port}`);
});
开发者ID:Dru89,项目名称:DefinitelyTyped,代码行数:29,代码来源:smtp-server-tests.ts

示例4: test_with_handlers_as_options

function test_with_handlers_as_options() {
    const options: SMTPServerOptions = {
        hideSTARTTLS: true,
        onConnect,
        onMailFrom,
        onRcptTo,
        onData,
        onClose,
    };

    const port = 2525;

    function onConnect(session: SMTPServerSession, callback: (err?: Error) => void): void {
        console.log(`[${session.id}] onConnect`);
        callback();
    }

    function onAuth(auth: SMTPServerAuthentication, session: SMTPServerSession, callback: (err: Error | undefined, response?: SMTPServerAuthenticationResponse) => void): void {
        if (auth.method === 'PLAIN' && auth.username === 'username' && auth.password === 'password') {
            callback(undefined, { user: auth.username });
        } else {
            callback(new Error('Invalid username or password'));
        }
    }

    function onMailFrom(from: SMTPServerAddress, session: SMTPServerSession, callback: (err?: Error) => void): void {
        console.log(`[${session.id}] onMailFrom ${from.address}`);
        if (from.address.split('@')[1] === 'spammer.com') {
            // code 421 disconnects SMTP session immediately
            callback(Object.assign(new Error('we do not like spam!'), { responseCode: 421 }));
        } else {
            callback();
        }
    }

    function onRcptTo(to: SMTPServerAddress, session: SMTPServerSession, callback: (err?: Error) => void): void {
        console.log(`[${session.id}] onRcptTo ${to.address}`);
        callback();
    }

    function onData(stream: Readable, session: SMTPServerSession, callback: (err?: Error) => void): void {
        console.log(`[${session.id}] onData started`);

        let messageLength = 0;

        stream.on('data', (chunk: Buffer) => {
            console.log(`[${session.id}] onData got data chunk ${chunk.length} bytes`);
            messageLength += chunk.length;
        });

        stream.once('end', () => {
            console.log(`[${session.id}] onData finished after reading ${messageLength} bytes`);
            callback();
        });
    }

    function onClose(session: SMTPServerSession) {
        console.log(`[${session.id}] onClose`);
    }

    const server = new SMTPServer(options);

    server.on('error', (err) => {
        console.log(`Server got error:`, err);
    });

    server.on('close', () => {
        console.log('Server closed');
    });

    server.listen(port, () => {
        const address = server.server.address() as AddressInfo;
        console.log(`Listening on [${address.address}]:${address.port}`);
    });

    server.close(() => {
        console.log('Server closed');
    });
}
开发者ID:Jeremy-F,项目名称:DefinitelyTyped,代码行数:79,代码来源:smtp-server-tests.ts


注:本文中的smtp-server.SMTPServer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。