Exemplo n.º 1
0
    def init_mailer_from_name(self, name):
        element = self.cfgtree.find('mailer[@name="%s"]' % name)
        if element is None:
            return None

        mail = Mail()
        mail.set_sender(element.find('from').text)
        mail.set_to(element.find('to').text)
        mail.set_subject(element.find('subject').text)
        mail.set_body(element.find('body').text)

        server = element.find('server').text
        return Mailer(server, mail)
Exemplo n.º 2
0
 def testConstructor(self):
     mail = Mail()
     self.assertNotEqual(mail.get_sender(), None)
     self.assertNotEqual(mail.get_sender(), '')
     user = getuser()
     self.assertTrue(mail.get_sender().startswith(user + '@'))
Exemplo n.º 3
0
 def setUp(self):
     self.mail = Mail(sender='test')
Exemplo n.º 4
0
from Exscript.util.mail import Mail
from TkExscript import MailWindow
mail = Mail(subject='Test me', body='hello world')
MailWindow(mail).mainloop()
Exemplo n.º 5
0
    def __init__(self,
                 parent,
                 mail=None,
                 server='localhost',
                 show_to=True,
                 show_cc=True,
                 show_bcc=False,
                 on_subject_changed=None):
        """
        A simple editor for sending emails. If the given mail is None, a
        new mail is created, else it is passed to attach().

        @type  parent: tkinter.Frame
        @param parent: The parent widget.
        @type  mail: Exscript.util.mail.Mail
        @param mail: The email object to attach.
        @type  server: string
        @param server: The address of the mailserver.
        @type  show_to: bool
        @param show_to: Whether to show the "To:" entry box.
        @type  show_cc: bool
        @param show_cc: Whether to show the "Cc:" entry box.
        @type  show_bcc: bool
        @param show_bcc: Whether to show the "Bcc:" entry box.
        @type  on_subject_changed: function
        @param on_subject_changed: Called whenever the subject changes.
        """
        Frame.__init__(self, parent)
        self.pack(expand=True, fill=BOTH)
        self.columnconfigure(0, pad=6)
        self.columnconfigure(1, weight=1)

        row = -1
        self.label_to = Label(self, text='To:')
        self.entry_to = Entry(self)
        if show_to:
            row += 1
            self.rowconfigure(row, pad=row > 0 and 6 or 0)
            self.label_to.grid(row=row, column=0, sticky=W)
            self.entry_to.grid(row=row, column=1, columnspan=2, sticky=W + E)
            self.entry_to.bind('<Key>', self._on_field_changed)

        self.label_cc = Label(self, text='Cc:')
        self.entry_cc = Entry(self)
        if show_cc:
            row += 1
            self.rowconfigure(row, pad=row > 0 and 6 or 0)
            self.label_cc.grid(row=row, column=0, sticky=W)
            self.entry_cc.grid(row=row, column=1, columnspan=2, sticky=W + E)
            self.entry_cc.bind('<Key>', self._on_field_changed)

        self.label_bcc = Label(self, text='Bcc:')
        self.entry_bcc = Entry(self)
        if show_bcc:
            row += 1
            self.rowconfigure(row, pad=row > 0 and 6 or 0)
            self.label_bcc.grid(row=row, column=0, sticky=W)
            self.entry_bcc.grid(row=row, column=1, columnspan=2, sticky=W + E)
            self.entry_bcc.bind('<Key>', self._on_field_changed)

        row += 1
        self.rowconfigure(row, pad=row > 0 and 6 or 0)
        self.label_subject = Label(self, text='Subject:')
        self.label_subject.grid(row=row, column=0, sticky=W)
        self.entry_subject = Entry(self)
        self.entry_subject.grid(row=row, column=1, columnspan=2, sticky=W + E)
        self.entry_subject.bind('<Key>', self._on_subject_changed)

        row += 1
        self.rowconfigure(row, pad=6, weight=1)
        scrollbar = Scrollbar(self, takefocus=0)
        scrollbar.grid(row=row, column=2, sticky=N + S)
        self.text_widget = Text(self)
        self.text_widget.grid(row=row,
                              column=0,
                              columnspan=2,
                              sticky=N + S + E + W)
        self.text_widget.config(yscrollcommand=scrollbar.set)
        self.text_widget.bind('<Key>', self._on_field_changed)
        scrollbar.config(command=self.text_widget.yview)

        row += 1
        self.rowconfigure(row, pad=6)
        self.buttons = _ButtonBar(self,
                                  on_cancel=parent.quit,
                                  on_send=self._on_send)
        self.buttons.grid(row=row, column=0, columnspan=3, sticky=E)

        self.server = server
        self.on_subject_changed_cb = on_subject_changed
        self.locked = False
        self.mail = None
        self.attach(mail and mail or Mail())