generateDiagnosticMessage static method
Generates a detailed diagnostic message.
Implementation
static String generateDiagnosticMessage(SmtpDiagnosticReport report) {
final buffer = StringBuffer();
buffer.writeln('=== SMTP Diagnostic Report ===');
buffer.writeln('Host: ${report.config.host}');
buffer.writeln('Port: ${report.config.port}');
buffer.writeln('Encryption: ${report.config.encryption}');
buffer.writeln('Timeout: ${report.config.timeout}s');
buffer.writeln();
if (report.hostResolved) {
buffer.writeln('✓ Host resolved: ${report.resolvedAddresses.join(', ')}');
} else {
buffer.writeln('✗ Host resolution failed');
}
if (report.portOpen) {
buffer.writeln('✓ Port ${report.config.port} is open');
buffer.writeln(' Connection time: ${report.connectionTime}ms');
} else {
buffer.writeln('✗ Port ${report.config.port} is closed or unreachable');
}
if (report.sslSupported) {
buffer.writeln('✓ SSL/TLS connection successful');
}
if (report.error != null) {
buffer.writeln();
buffer.writeln('Error: ${report.error}');
}
buffer.writeln();
buffer.writeln('Recommendations:');
if (!report.hostResolved) {
buffer.writeln('• Check that the SMTP hostname is correct');
buffer.writeln('• Verify your DNS settings');
buffer.writeln('• Check your internet connection');
} else if (!report.portOpen) {
buffer.writeln('• Verify the SMTP port is correct');
buffer.writeln(' - Common ports: 25 (plain), 587 (TLS), 465 (SSL)');
buffer.writeln(
'• Check firewall settings (allow outbound on port ${report.config.port})',
);
buffer.writeln('• Verify the SMTP server is running');
buffer.writeln('• Try increasing the timeout value');
} else if (report.success) {
buffer.writeln('• Connection successful! The SMTP server is reachable.');
buffer.writeln(
'• If authentication still fails, check username/password',
);
}
buffer.writeln();
buffer.writeln('Total diagnostic time: ${report.totalTime}ms');
return buffer.toString();
}