LinuxCommandLibrary

msgen

Create message catalog from template file

SYNOPSIS

msgen [options] [header value ...]

PARAMETERS

-h, --help
    Display help information and exit.

-v, --version
    Display version information and exit.

-d, --date=date
    Set the Date: header field. If not specified, a current date will be used.

-m, --message-id=id
    Set the Message-ID: header field. If not specified, a unique ID will be generated.

-r, --from=address
    Set the From: header field. If not specified, it defaults to the current user's email address.

-t, --to=address
    Set the To: header field.

-c, --cc=address
    Set the Cc: header field.

-b, --bcc=address
    Set the Bcc: header field.

-s, --subject=subject
    Set the Subject: header field.

-a, --add-header=NAME: VALUE
    Add an arbitrary header field. This option can be used multiple times.

-i, --ignore-input
    Do not read message body from standard input.

-e, --add-newline
    Ensure the message body ends with a newline character.

--auto-decode
    Attempt to decode RFC 2047 encoded header fields (default behavior).

--no-auto-decode
    Disable RFC 2047 header decoding.

--charset=charset
    Specify the default character set for the Content-Type header (e.g., utf-8).

--output-charset=charset
    Convert the message body to the specified character set before output.

--encode
    Add a Content-Transfer-Encoding header if missing and encode the body (e.g., Base64 or Quoted-Printable).

--rfc2047-encode
    Force RFC 2047 encoding for specified header fields if non-ASCII characters are present.

--input-file=file
    Read message body from the specified file instead of standard input.

header value ...
    Any remaining arguments are interpreted as header NAME: VALUE pairs, which are added to the message. These have the highest precedence.

DESCRIPTION

msgen is a utility from the GNU Mailutils package designed to create email messages conforming to RFC 822 and RFC 2822 standards.
It is particularly useful for scripting mail operations or when you need to construct a message with specific headers that might otherwise be automatically generated or omitted by standard mail commands. msgen can populate missing essential headers such as Date, Message-ID, From, and To, ensuring the generated output is a complete and valid mail message.
Users can provide initial header fields as command-line arguments, or msgen can read the message body from standard input. It ensures the message includes a Content-Type header, typically text/plain; charset=us-ascii by default, but this can be overridden. msgen is often used as a backend for other mail utilities or in shell scripts requiring precise control over mail message structure.

CAVEATS

msgen focuses on creating syntactically correct messages, but it does not handle sending them; it outputs to standard output. RFC compliance is a primary goal, so unexpected input might lead to strict formatting or errors. When using the --encode option, msgen attempts to determine the best encoding (Base64 or Quoted-Printable) based on the content. It is part of the mailutils package, so it may not be universally available on all Linux systems by default and might require separate installation.

OUTPUT BEHAVIOR

msgen prints the fully formed RFC 822/2822 message to standard output. This output can then be piped to another command like sendmail or mail for actual delivery or further processing.

HEADER PRECEDENCE

Headers specified as command-line options (e.g., via -s for Subject) take precedence over auto-generated ones. Explicit NAME: VALUE pairs provided as non-option arguments have the highest precedence, allowing users to override headers set by options like -s or -t, or to add arbitrary new headers.

HISTORY

msgen is a component of the GNU Mailutils project, which aims to provide a robust and interoperable set of mail utilities for Linux and Unix-like systems. Its development began in the late 1990s, evolving as a modern successor to older, less standardized mail tools. The command specifically addresses the need for a programmatic and precise way to construct RFC-compliant email messages. This is crucial for automated scripts, mail gateways, and advanced mail processing, especially as email standards evolved to support various character sets and content types. msgen fills a gap where simple echo "..." | mail commands lack the fine-grained control over crucial headers and encoding required for complex or multi-lingual messages.

SEE ALSO

mail(1), sendmail(8), formail(1), mailx(1), mutt(1)

Copied to clipboard