1# -*- coding: utf-8 -*-
2
3# Send the same mail to a list of people, one at a time.
4# As this is normal Python code, the message contents and
5# the addresses could also come from an external source
6# (such as a file, or a database).
7addresses = ["mail1@example.tld", "mail2@example.tld", "mail3@example.tld"]
8
9for address in addresses:
10    # The argument for the constructor is an email address on which
11    # the sending account is selected.
12    # It's also possible to use the default constructor without arguments,
13    # in which case the same rules as on a menu click one "New message"
14    # are applied.
15    cw = clawsmail.ComposeWindow("berndth@gmx.de")
16
17    # Add a recipient. There are also add_Cc and add_Bcc functions.
18    cw.add_To(address)
19
20    # Set the subject of the message
21    cw.set_subject("Mass mail")
22
23    # For the message body, access to the GtkTextView is granted in ComposeWindow.text.
24    buffer = cw.text.get_buffer()
25    buffer.set_text("This is an automatic message")
26
27    # Access to the GtkUIManager is also provided, look for "send later" action
28    action = None
29    for action_group in cw.ui_manager.get_action_groups():
30        for action in action_group.list_actions():
31            action = action_group.get_action("Message/SendLater")
32            if action:
33                break
34        if action:
35            break;
36    if action:
37        action.activate()
38
39# Finally, the action group of the main window can be used to send the messages out
40# Comment this for now, to not actually send stuff during testing
41#clawsmail.get_mainwindow_action_group().get_action("Message/SendQueue").activate()
42