##// END OF EJS Templates
smtp: fix for server doesn't support starttls extension...
Zhigang Wang -
r13201:f0525057 default
parent child Browse files
Show More
@@ -709,8 +709,8 b' Configuration for extensions that need t'
709 ``port``
709 ``port``
710 Optional. Port to connect to on mail server. Default: 25.
710 Optional. Port to connect to on mail server. Default: 25.
711 ``tls``
711 ``tls``
712 Optional. Whether to connect to mail server using TLS. True or
712 Optional. Method to enable TLS when connecting to mail server: starttls,
713 False. Default: False.
713 smtps or none. Default: none.
714 ``username``
714 ``username``
715 Optional. User name for authenticating with the SMTP server.
715 Optional. User name for authenticating with the SMTP server.
716 Default: none.
716 Default: none.
@@ -33,7 +33,17 b" email.Header.Header.__dict__['__init__']"
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'))
@@ -41,11 +51,8 b' def _smtp(ui):'
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()
General Comments 0
You need to be logged in to leave comments. Login now