addmembers.rst 4.54 KB
Newer Older
1 2 3 4 5 6 7
==============
Adding members
==============

The ``mailman addmembers`` command allows a site administrator to add members
to a mailing list.

8
    >>> from mailman.testing.documentation import cli
9 10
    >>> command = cli('mailman.commands.cli_addmembers.addmembers')

11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
Usage
-----

Here is the complete usage for the command.
::

    >>> command('mailman addmembers --help')
    Usage: addmembers [OPTIONS] FILENAME LISTSPEC
    <BLANKLINE>
      Add all member addresses in FILENAME with delivery mode as specified with
      -d/--delivery.  FILENAME can be '-' to indicate standard input. Blank lines
      and lines that start with a '#' are ignored.
    <BLANKLINE>
    Options:
      -d, --delivery [regular|mime|plain|summary|disabled]
                                      Set the added members delivery mode to
                                      'regular', 'mime', 'plain', 'summary' or
                                      'disabled'.  I.e., one of regular, three modes
                                      of digest or no delivery.  If not given, the
30 31
                                      default is regular.  Ignored for invited
                                      members.
32
    <BLANKLINE>
33 34
      -i, --invite                    Send the added members an invitation rather
                                      than immediately adding them.
35 36 37 38 39 40 41 42 43 44
    <BLANKLINE>
      -w, --welcome-msg / -W, --no-welcome-msg
                                      Override the list's setting for
                                      send_welcome_message.
    <BLANKLINE>
      --help                          Show this message and exit.

Examples
--------

45 46 47 48 49 50 51
You can add members to a mailing list from the command line.  To do so, you
need a file containing email addresses and optional display names that can be
parsed by ``email.utils.parseaddr()``.
::

    >>> from tempfile import NamedTemporaryFile
    >>> filename = cleanups.enter_context(NamedTemporaryFile()).name
52
    >>> from mailman.app.lifecycle import create_list    
53 54 55 56 57 58 59 60 61 62
    >>> bee = create_list('bee@example.com')
    >>> with open(filename, 'w', encoding='utf-8') as fp:
    ...     print("""\
    ... aperson@example.com
    ... Bart Person <bperson@example.com>
    ... cperson@example.com (Cate Person)
    ... """, file=fp)

    >>> command('mailman addmembers ' + filename + ' bee.example.com')

63
    >>> from mailman.testing.documentation import dump_list
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
    >>> from operator import attrgetter
    >>> dump_list(bee.members.addresses, key=attrgetter('email'))
    aperson@example.com
    Bart Person <bperson@example.com>
    Cate Person <cperson@example.com>

You can also specify ``-`` as the filename, in which case the addresses are
taken from standard input.
::

    >>> stdin = """\
    ... dperson@example.com
    ... Elly Person <eperson@example.com>
    ... fperson@example.com (Fred Person)
    ... """
    >>> command('mailman addmembers - bee.example.com', input=stdin)

    >>> dump_list(bee.members.addresses, key=attrgetter('email'))
    aperson@example.com
    Bart Person <bperson@example.com>
    Cate Person <cperson@example.com>
    dperson@example.com
    Elly Person <eperson@example.com>
    Fred Person <fperson@example.com>

Blank lines and lines that begin with '#' are ignored.
::

    >>> with open(filename, 'w', encoding='utf-8') as fp:
    ...     print("""\
    ... gperson@example.com
    ... # hperson@example.com
    ...
    ... iperson@example.com
    ... """, file=fp)

    >>> command('mailman addmembers ' + filename + ' bee.example.com')

    >>> dump_list(bee.members.addresses, key=attrgetter('email'))
    aperson@example.com
    Bart Person <bperson@example.com>
    Cate Person <cperson@example.com>
    dperson@example.com
    Elly Person <eperson@example.com>
    Fred Person <fperson@example.com>
    gperson@example.com
    iperson@example.com

Addresses which are already subscribed are ignored, although a warning is
printed.
::

    >>> with open(filename, 'w', encoding='utf-8') as fp:
    ...     print("""\
    ... gperson@example.com
    ... aperson@example.com
    ... jperson@example.com
    ... """, file=fp)

    >>> command('mailman addmembers ' + filename + ' bee.example.com')
    Already subscribed (skipping): gperson@example.com
    Already subscribed (skipping): aperson@example.com

    >>> dump_list(bee.members.addresses, key=attrgetter('email'))
    aperson@example.com
    Bart Person <bperson@example.com>
    Cate Person <cperson@example.com>
    dperson@example.com
    Elly Person <eperson@example.com>
    Fred Person <fperson@example.com>
    gperson@example.com
    iperson@example.com
    jperson@example.com