/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/smtp_connection.py

  • Committer: Jelmer Vernooij
  • Date: 2017-02-05 17:00:29 UTC
  • mto: (6621.2.1 py3)
  • mto: This revision was merged to the branch mainline in revision 6624.
  • Revision ID: jelmer@jelmer.uk-20170205170029-s01xdro0hkixhq3r
Convert some octal numbers to new notations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""A convenience class around smtplib."""
18
18
 
 
19
from __future__ import absolute_import
 
20
 
19
21
from email import Utils
20
22
import errno
21
23
import smtplib
33
35
    )
34
36
 
35
37
 
 
38
smtp_password = config.Option('smtp_password', default=None,
 
39
        help='''\
 
40
Password to use for authentication to SMTP server.
 
41
''')
 
42
smtp_server = config.Option('smtp_server', default=None,
 
43
        help='''\
 
44
Hostname of the SMTP server to use for sending email.
 
45
''')
 
46
smtp_username = config.Option('smtp_username', default=None,
 
47
        help='''\
 
48
Username to use for authentication to SMTP server.
 
49
''')
 
50
 
 
51
 
36
52
class SMTPConnection(object):
37
53
    """Connect to an SMTP server and send an email.
38
54
 
48
64
        if self._smtp_factory is None:
49
65
            self._smtp_factory = smtplib.SMTP
50
66
        self._config = config
51
 
        self._config_smtp_server = config.get_user_option('smtp_server')
 
67
        self._config_smtp_server = config.get('smtp_server')
52
68
        self._smtp_server = self._config_smtp_server
53
69
        if self._smtp_server is None:
54
70
            self._smtp_server = self._default_smtp_server
55
71
 
56
 
        self._smtp_username = config.get_user_option('smtp_username')
57
 
        self._smtp_password = config.get_user_option('smtp_password')
 
72
        self._smtp_username = config.get('smtp_username')
 
73
        self._smtp_password = config.get('smtp_password')
58
74
 
59
75
        self._connection = None
60
76
 
74
90
        self._connection = self._smtp_factory()
75
91
        try:
76
92
            self._connection.connect(self._smtp_server)
77
 
        except socket.error, e:
 
93
        except socket.error as e:
78
94
            if e.args[0] == errno.ECONNREFUSED:
79
95
                if self._config_smtp_server is None:
80
96
                    raise DefaultSMTPConnectionRefused(socket.error,
165
181
            self._connect()
166
182
            self._connection.sendmail(from_email, to_emails,
167
183
                                      message.as_string())
168
 
        except smtplib.SMTPRecipientsRefused, e:
 
184
        except smtplib.SMTPRecipientsRefused as e:
169
185
            raise SMTPError('server refused recipient: %d %s' %
170
186
                    e.recipients.values()[0])
171
 
        except smtplib.SMTPResponseException, e:
 
187
        except smtplib.SMTPResponseException as e:
172
188
            raise SMTPError('%d %s' % (e.smtp_code, e.smtp_error))
173
 
        except smtplib.SMTPException, e:
 
189
        except smtplib.SMTPException as e:
174
190
            raise SMTPError(str(e))