31 email.Header.Header.__dict__['__init__'] = _unifiedheaderinit |
31 email.Header.Header.__dict__['__init__'] = _unifiedheaderinit |
32 |
32 |
33 def _smtp(ui): |
33 def _smtp(ui): |
34 '''build an smtp connection and return a function to send mail''' |
34 '''build an smtp connection and return a function to send mail''' |
35 local_hostname = ui.config('smtp', 'local_hostname') |
35 local_hostname = ui.config('smtp', 'local_hostname') |
36 s = smtplib.SMTP(local_hostname=local_hostname) |
36 tls = ui.config('smtp', 'tls') |
|
37 # backward compatible: when tls = true, we use starttls. |
|
38 starttls = tls == 'starttls' or util.parsebool(tls) |
|
39 smtps = tls == 'smtps' |
|
40 if (starttls or smtps) and not hasattr(socket, 'ssl'): |
|
41 raise util.Abort(_("can't use TLS: Python SSL support not installed")) |
|
42 if smtps: |
|
43 ui.note(_('(using smtps)\n')) |
|
44 s = smtplib.SMTP_SSL(local_hostname=local_hostname) |
|
45 else: |
|
46 s = smtplib.SMTP(local_hostname=local_hostname) |
37 mailhost = ui.config('smtp', 'host') |
47 mailhost = ui.config('smtp', 'host') |
38 if not mailhost: |
48 if not mailhost: |
39 raise util.Abort(_('smtp.host not configured - cannot send mail')) |
49 raise util.Abort(_('smtp.host not configured - cannot send mail')) |
40 mailport = util.getport(ui.config('smtp', 'port', 25)) |
50 mailport = util.getport(ui.config('smtp', 'port', 25)) |
41 ui.note(_('sending mail: smtp host %s, port %s\n') % |
51 ui.note(_('sending mail: smtp host %s, port %s\n') % |
42 (mailhost, mailport)) |
52 (mailhost, mailport)) |
43 s.connect(host=mailhost, port=mailport) |
53 s.connect(host=mailhost, port=mailport) |
44 if ui.configbool('smtp', 'tls'): |
54 if starttls: |
45 if not hasattr(socket, 'ssl'): |
55 ui.note(_('(using starttls)\n')) |
46 raise util.Abort(_("can't use TLS: Python SSL support " |
|
47 "not installed")) |
|
48 ui.note(_('(using tls)\n')) |
|
49 s.ehlo() |
56 s.ehlo() |
50 s.starttls() |
57 s.starttls() |
51 s.ehlo() |
58 s.ehlo() |
52 username = ui.config('smtp', 'username') |
59 username = ui.config('smtp', 'username') |
53 password = ui.config('smtp', 'password') |
60 password = ui.config('smtp', 'password') |