if I want to wrap a function that use a a result and pass the same result to the next.
Future<Socket> _socket(SocketConfig config) =>
Socket.connect(config.host, config.port);
Future<void> sendEmail(EmailData data) async {
// Connect to the SMTP server
_socket
.runAsync(data.config)
// Wait for the server's greeting message
.thenRunVoid((socket) => socket.first);
/// TODO
}
// Send EHLO command to initiate the conversation
// .thenRunVoid((socket) => socket.first)
// //socket.writeln('EHLO ${data.payload.ehlo}');
eg.
import 'dart:convert';
import 'dart:io';
void main() async {
// Connect to the SMTP server
final socket = await Socket.connect('smtp.example.com', 25);
// Wait for the server's greeting message
await socket.first;
// Send EHLO command to initiate the conversation
socket.writeln('EHLO example.com');
await socket.flush();
// Read and discard server response
await socket.first;
// Send MAIL FROM command
socket.writeln('MAIL FROM:<sender@example.com>');
await socket.flush();
await socket.first;
// Send RCPT TO command
socket.writeln('RCPT TO:<recipient@example.com>');
await socket.flush();
await socket.first;
// Send DATA command to start email data
socket.writeln('DATA');
await socket.flush();
await socket.first;
// Send email content
socket.writeln('Subject: Test Email');
socket.writeln('From: <sender@example.com>');
socket.writeln('To: <recipient@example.com>');
socket.writeln('');
socket.writeln('This is a test email.');
socket.writeln('.');
// Flush the socket and read server response
await socket.flush();
await socket.first;
// Send QUIT command to close the connection
socket.writeln('QUIT');
await socket.flush();
// Close the socket
await socket.close();
}
if I want to wrap a function that use a a result and pass the same result to the next.
eg.