genmail

Command Line Email Sender

CLI for sending emails via SMTP with authentication and SSL/TLS options.

A simple command-line tool for sending emails via SMTP with support for various authentication methods and SSL/TLS modes.

Synopsis

genmail --server <host> --port <port> --from <addr> --to <addr> --subject <text> [options]

Required Options

Option Description
--server <host> SMTP server hostname or IP address
--port <port> SMTP server port number
--from <addr> Sender email address
--to <addr> Recipient email address (can be repeated for multiple recipients)
--subject <text> Email subject line

Optional Options

Option Default Description
--auth plain|none plain Authentication mode
--user <user> SMTP username (required when --auth plain)
--pass <pass> SMTP password (required when --auth plain)
--ssl none|ssl|tls|starttls none SSL/TLS mode
--ignoressl false Skip TLS certificate validation (useful for testing)
--debug false Print SMTP conversation to stderr
--html yes|no no Send body as HTML content
--cc <addr> CC recipient (can be repeated)
--bcc <addr> BCC recipient (can be repeated)
--body <text> Email body text (if omitted, reads from stdin)

SSL/TLS Modes Explained

Mode Description Typical Port
none No encryption (plain text) 25
ssl or tls Implicit TLS - connection is encrypted from the start 465
starttls Explicit TLS - starts plain, then upgrades to TLS 587

Authentication Modes

Mode Description
plain SMTP PLAIN authentication (requires --user and --pass)
none No authentication (server must allow relay)

Note: Additional authentication modes (login, cram-md5, digest-md5, xoauth2, scram) are not currently implemented. The tool supports plain and none only.

Body Input

The email body can be provided in two ways:

  1. Command line argument: Use --body "your message here"
  2. Standard input: Pipe or type the body content if --body is omitted

Examples

Basic Email (No Authentication, No SSL)

For testing on a local mail server or trusted network:

genmail \
  --server mail.example.com \
  --port 25 \
  --auth none \
  --ssl none \
  --from sender@example.com \
  --to recipient@example.com \
  --subject "Test Message" \
  --body "Hello, this is a test email."

Gmail with STARTTLS

Gmail requires authentication and uses STARTTLS on port 587:

genmail \
  --server smtp.gmail.com \
  --port 587 \
  --auth plain \
  --user yourname@gmail.com \
  --pass "your-app-password" \
  --ssl starttls \
  --from yourname@gmail.com \
  --to recipient@example.com \
  --subject "Gmail Test" \
  --body "Sent via Gmail SMTP"

Note: Gmail requires an "App Password" for SMTP authentication. Generate one in your Google Account security settings.

Office 365 with STARTTLS

Microsoft 365 also uses STARTTLS on port 587:

genmail \
  --server smtp.office365.com \
  --port 587 \
  --auth plain \
  --user yourname@yourdomain.com \
  --pass "your-password" \
  --ssl starttls \
  --from yourname@yourdomain.com \
  --to recipient@example.com \
  --subject "Office 365 Test" \
  --body "Sent via Office 365 SMTP"

Implicit TLS (Port 465)

Some providers use implicit TLS (SSL) on port 465:

genmail \
  --server mail.example.com \
  --port 465 \
  --auth plain \
  --user yourname@example.com \
  --pass "your-password" \
  --ssl ssl \
  --from yourname@example.com \
  --to recipient@example.com \
  --subject "SSL Email Test" \
  --body "Sent via implicit TLS"

SendGrid Example

SendGrid uses port 587 with STARTTLS:

genmail \
  --server smtp.sendgrid.net \
  --port 587 \
  --auth plain \
  --user apikey \
  --pass "your-sendgrid-api-key" \
  --ssl starttls \
  --from noreply@yourdomain.com \
  --to customer@example.com \
  --subject "SendGrid Test" \
  --body "Sent via SendGrid"

Amazon SES Example

Amazon SES uses port 587 with STARTTLS:

genmail \
  --server email-smtp.us-east-1.amazonaws.com \
  --port 587 \
  --auth plain \
  --user "your-ses-smtp-username" \
  --pass "your-ses-smtp-password" \
  --ssl starttls \
  --from sender@yourdomain.com \
  --to recipient@example.com \
  --subject "SES Test" \
  --body "Sent via Amazon SES"

Multiple Recipients

Send to multiple To, CC, and BCC recipients:

genmail \
  --server smtp.example.com \
  --port 587 \
  --auth plain \
  --user yourname@example.com \
  --pass "your-password" \
  --ssl starttls \
  --from yourname@example.com \
  --to alice@example.com \
  --to bob@example.com \
  --cc carol@example.com \
  --cc dave@example.com \
  --bcc archive@example.com \
  --subject "Team Update" \
  --body "Hello team, this is an update."

HTML Email

Send an HTML formatted email:

genmail \
  --server smtp.example.com \
  --port 587 \
  --auth plain \
  --user yourname@example.com \
  --pass "your-password" \
  --ssl starttls \
  --from yourname@example.com \
  --to recipient@example.com \
  --subject "HTML Email" \
  --html yes \
  --body "<h1>Welcome</h1><p>This is an <strong>HTML</strong> email.</p>"

Body from File (Piped Input)

Read the email body from a file:

cat email-template.txt | genmail \
  --server smtp.example.com \
  --port 587 \
  --auth plain \
  --user yourname@example.com \
  --pass "your-password" \
  --ssl starttls \
  --from yourname@example.com \
  --to recipient@example.com \
  --subject "Generated Report"

Body from Heredoc

Use a heredoc for multi-line body content:

genmail \
  --server smtp.example.com \
  --port 587 \
  --auth plain \
  --user yourname@example.com \
  --pass "your-password" \
  --ssl starttls \
  --from yourname@example.com \
  --to recipient@example.com \
  --subject "Multi-line Message" <<EOF
Dear Customer,

This is a multi-line email message.

Best regards,
The Team
EOF

Debug Mode

Enable debug mode to see the SMTP conversation (useful for troubleshooting):

genmail \
  --server smtp.example.com \
  --port 587 \
  --auth plain \
  --user yourname@example.com \
  --pass "your-password" \
  --ssl starttls \
  --from yourname@example.com \
  --to recipient@example.com \
  --subject "Debug Test" \
  --body "Testing with debug enabled" \
  --debug

Debug output shows the client commands (C:) and server responses (S:):

C: EHLO localhost
S: 250-smtp.example.com Hello
S: 250-SIZE 35882577
S: 250-STARTTLS
S: 250 AUTH PLAIN
C: STARTTLS
S: 220 Ready to start TLS
C: EHLO localhost
S: 250 AUTH PLAIN
C: AUTH PLAIN ...
S: 235 Authentication successful
C: MAIL FROM:<yourname@example.com>
S: 250 OK
C: RCPT TO:<recipient@example.com>
S: 250 Accepted
C: DATA
S: 354 Enter message
C: QUIT
S: 221 Bye

Testing with Self-Signed Certificates

When testing against a server with self-signed certificates, use --ignoressl:

genmail \
  --server mail.internal.local \
  --port 465 \
  --auth plain \
  --user testuser \
  --pass testpass \
  --ssl ssl \
  --ignoressl \
  --from test@internal.local \
  --to admin@internal.local \
  --subject "Internal Test" \
  --body "Testing internal mail server"

Warning: Never use --ignoressl in production environments as it disables certificate verification.

No Authentication (Open Relay)

For internal mail servers that don't require authentication:

genmail \
  --server relay.internal.local \
  --port 25 \
  --auth none \
  --ssl none \
  --from app@internal.local \
  --to admin@internal.local \
  --subject "System Alert" \
  --body "Server backup completed successfully"

Exit Codes

Code Description
0 Success - email sent
1 Failure - email could not be sent
2 Error - invalid arguments or configuration

Common Issues

Authentication Failed

  • Verify your username and password.
  • For Gmail, ensure you're using an App Password, not your account password.
  • Check if 2FA is enabled and requires an app-specific password.

Connection Refused

  • Verify the server hostname and port.
  • Check if the SMTP service is running.
  • Ensure firewall allows outbound connections on the specified port.

TLS/SSL Errors

  • Try a different SSL mode (--ssl ssl vs --ssl starttls).
  • Use --ignoressl for testing with self-signed certificates.
  • Verify the server supports the SSL mode you're using.

Relay Denied

  • Ensure you're authenticating if the server requires it.
  • Verify the "from" address is allowed by the server.
  • Check if the server allows relay for your IP address.