Repository: buildbot/buildbot

Issue:
Mail notifier SMTP error
I'm trying to get mail working in buildbot 0.9.10.  It used to work in our 0.8 setup.  I have the following in master.cfg:


c['services'] = []
m = reporters.MailNotifier(fromaddr='buildbot@ikm189l',
                           sendToInterestedUsers=False,
                           extraRecipients=['jlquinn@us.ibm.com'],
                           mode=('all'))
c['services'].append(m)

When I kick off a build that fails, I see the following in the log file.  I verified I can send an email from the buildbot machine from the cmdline and it arrives as expected.


2017-09-19 20:08:39-0400 [-] sending mail (922 bytes) to ['jlquinn@us.ibm.com']
2017-09-19 20:08:39-0400 [-] Starting factory <twisted.mail.smtp.ESMTPSenderFactory instance at 0x7f6098103cf8>
2017-09-19 20:08:39-0400 [ESMTPSender,client] Unhandled Error
	Traceback (most recent call last):
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/python/log.py", line 103, in callWithLogger
	    return callWithContext({"system": lp}, func, *args, **kw)
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/python/log.py", line 86, in callWithContext
	    return context.call({ILogContext: newCtx}, func, *args, **kw)
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/python/context.py", line 122, in callWithContext
	    return self.currentContext().callWithContext(ctx, func, *args, **kw)
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/python/context.py", line 85, in callWithContext
	    return func(*args,**kw)
	--- <exception caught here> ---
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/internet/posixbase.py", line 597, in _doReadOrWrite
	    why = selectable.doRead()
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/internet/tcp.py", line 208, in doRead
	    return self._dataReceived(data)
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/internet/tcp.py", line 214, in _dataReceived
	    rval = self.protocol.dataReceived(data)
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/protocols/basic.py", line 571, in dataReceived
	    why = self.lineReceived(line)
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/mail/smtp.py", line 995, in lineReceived
	    why = self._okresponse(self.code, b'\n'.join(self.resp))
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/mail/smtp.py", line 1044, in smtpState_to
	    return self.smtpState_toOrData(0, b'')
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/mail/smtp.py", line 1062, in smtpState_toOrData
	    self.sendLine(b'RCPT TO:' + quoteaddr(self.lastAddress))
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/mail/smtp.py", line 179, in quoteaddr
	    res = email.utils.parseaddr(addr)
	  File "/opt/buildbot/sandbox/lib/python2.7/email/utils.py", line 214, in parseaddr
	    addrs = _AddressList(addr).addresslist
	  File "/opt/buildbot/sandbox/lib/python2.7/email/_parseaddr.py", line 457, in __init__
	    self.addresslist = self.getaddrlist()
	  File "/opt/buildbot/sandbox/lib/python2.7/email/_parseaddr.py", line 217, in getaddrlist
	    while self.pos < len(self.field):
	exceptions.TypeError: object of type 'module' has no len()
	
2017-09-19 20:08:39-0400 [ESMTPSender,client] SMTP Client retrying server. Retry: 5
2017-09-19 20:08:39-0400 [ESMTPSender,client] Unhandled Error
	Traceback (most recent call last):
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/python/log.py", line 103, in callWithLogger
	    return callWithContext({"system": lp}, func, *args, **kw)
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/python/log.py", line 86, in callWithContext
	    return context.call({ILogContext: newCtx}, func, *args, **kw)
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/python/context.py", line 122, in callWithContext
	    return self.currentContext().callWithContext(ctx, func, *args, **kw)
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/python/context.py", line 85, in callWithContext
	    return func(*args,**kw)
	--- <exception caught here> ---
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/internet/posixbase.py", line 597, in _doReadOrWrite
	    why = selectable.doRead()
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/internet/tcp.py", line 208, in doRead
	    return self._dataReceived(data)
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/internet/tcp.py", line 214, in _dataReceived
	    rval = self.protocol.dataReceived(data)
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/protocols/basic.py", line 571, in dataReceived
	    why = self.lineReceived(line)
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/mail/smtp.py", line 995, in lineReceived
	    why = self._okresponse(self.code, b'\n'.join(self.resp))
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/mail/smtp.py", line 1044, in smtpState_to
	    return self.smtpState_toOrData(0, b'')
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/mail/smtp.py", line 1062, in smtpState_toOrData
	    self.sendLine(b'RCPT TO:' + quoteaddr(self.lastAddress))
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/mail/smtp.py", line 179, in quoteaddr
	    res = email.utils.parseaddr(addr)
	  File "/opt/buildbot/sandbox/lib/python2.7/email/utils.py", line 214, in parseaddr
	    addrs = _AddressList(addr).addresslist
	  File "/opt/buildbot/sandbox/lib/python2.7/email/_parseaddr.py", line 457, in __init__
	    self.addresslist = self.getaddrlist()
	  File "/opt/buildbot/sandbox/lib/python2.7/email/_parseaddr.py", line 217, in getaddrlist
	    while self.pos < len(self.field):
	exceptions.TypeError: object of type 'module' has no len()
	
2017-09-19 20:08:39-0400 [ESMTPSender,client] SMTP Client retrying server. Retry: 4
2017-09-19 20:08:39-0400 [ESMTPSender,client] Unhandled Error
	Traceback (most recent call last):
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/python/log.py", line 103, in callWithLogger
	    return callWithContext({"system": lp}, func, *args, **kw)
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/python/log.py", line 86, in callWithContext
	    return context.call({ILogContext: newCtx}, func, *args, **kw)
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/python/context.py", line 122, in callWithContext
	    return self.currentContext().callWithContext(ctx, func, *args, **kw)
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/python/context.py", line 85, in callWithContext
	    return func(*args,**kw)
	--- <exception caught here> ---
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/internet/posixbase.py", line 597, in _doReadOrWrite
	    why = selectable.doRead()
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/internet/tcp.py", line 208, in doRead
	    return self._dataReceived(data)
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/internet/tcp.py", line 214, in _dataReceived
	    rval = self.protocol.dataReceived(data)
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/protocols/basic.py", line 571, in dataReceived
	    why = self.lineReceived(line)
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/mail/smtp.py", line 995, in lineReceived
	    why = self._okresponse(self.code, b'\n'.join(self.resp))
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/mail/smtp.py", line 1044, in smtpState_to
	    return self.smtpState_toOrData(0, b'')
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/mail/smtp.py", line 1062, in smtpState_toOrData
	    self.sendLine(b'RCPT TO:' + quoteaddr(self.lastAddress))
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/mail/smtp.py", line 179, in quoteaddr
	    res = email.utils.parseaddr(addr)
	  File "/opt/buildbot/sandbox/lib/python2.7/email/utils.py", line 214, in parseaddr
	    addrs = _AddressList(addr).addresslist
	  File "/opt/buildbot/sandbox/lib/python2.7/email/_parseaddr.py", line 457, in __init__
	    self.addresslist = self.getaddrlist()
	  File "/opt/buildbot/sandbox/lib/python2.7/email/_parseaddr.py", line 217, in getaddrlist
	    while self.pos < len(self.field):
	exceptions.TypeError: object of type 'module' has no len()
	
2017-09-19 20:08:39-0400 [ESMTPSender,client] SMTP Client retrying server. Retry: 3
2017-09-19 20:08:39-0400 [ESMTPSender,client] Unhandled Error
	Traceback (most recent call last):
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/python/log.py", line 103, in callWithLogger
	    return callWithContext({"system": lp}, func, *args, **kw)
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/python/log.py", line 86, in callWithContext
	    return context.call({ILogContext: newCtx}, func, *args, **kw)
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/python/context.py", line 122, in callWithContext
	    return self.currentContext().callWithContext(ctx, func, *args, **kw)
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/python/context.py", line 85, in callWithContext
	    return func(*args,**kw)
	--- <exception caught here> ---
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/internet/posixbase.py", line 597, in _doReadOrWrite
	    why = selectable.doRead()
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/internet/tcp.py", line 208, in doRead
	    return self._dataReceived(data)
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/internet/tcp.py", line 214, in _dataReceived
	    rval = self.protocol.dataReceived(data)
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/protocols/basic.py", line 571, in dataReceived
	    why = self.lineReceived(line)
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/mail/smtp.py", line 995, in lineReceived
	    why = self._okresponse(self.code, b'\n'.join(self.resp))
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/mail/smtp.py", line 1044, in smtpState_to
	    return self.smtpState_toOrData(0, b'')
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/mail/smtp.py", line 1062, in smtpState_toOrData
	    self.sendLine(b'RCPT TO:' + quoteaddr(self.lastAddress))
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/mail/smtp.py", line 179, in quoteaddr
	    res = email.utils.parseaddr(addr)
	  File "/opt/buildbot/sandbox/lib/python2.7/email/utils.py", line 214, in parseaddr
	    addrs = _AddressList(addr).addresslist
	  File "/opt/buildbot/sandbox/lib/python2.7/email/_parseaddr.py", line 457, in __init__
	    self.addresslist = self.getaddrlist()
	  File "/opt/buildbot/sandbox/lib/python2.7/email/_parseaddr.py", line 217, in getaddrlist
	    while self.pos < len(self.field):
	exceptions.TypeError: object of type 'module' has no len()
	
2017-09-19 20:08:39-0400 [ESMTPSender,client] SMTP Client retrying server. Retry: 2
2017-09-19 20:08:39-0400 [ESMTPSender,client] Unhandled Error
	Traceback (most recent call last):
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/python/log.py", line 103, in callWithLogger
	    return callWithContext({"system": lp}, func, *args, **kw)
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/python/log.py", line 86, in callWithContext
	    return context.call({ILogContext: newCtx}, func, *args, **kw)
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/python/context.py", line 122, in callWithContext
	    return self.currentContext().callWithContext(ctx, func, *args, **kw)
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/python/context.py", line 85, in callWithContext
	    return func(*args,**kw)
	--- <exception caught here> ---
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/internet/posixbase.py", line 597, in _doReadOrWrite
	    why = selectable.doRead()
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/internet/tcp.py", line 208, in doRead
	    return self._dataReceived(data)
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/internet/tcp.py", line 214, in _dataReceived
	    rval = self.protocol.dataReceived(data)
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/protocols/basic.py", line 571, in dataReceived
	    why = self.lineReceived(line)
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/mail/smtp.py", line 995, in lineReceived
	    why = self._okresponse(self.code, b'\n'.join(self.resp))
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/mail/smtp.py", line 1044, in smtpState_to
	    return self.smtpState_toOrData(0, b'')
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/mail/smtp.py", line 1062, in smtpState_toOrData
	    self.sendLine(b'RCPT TO:' + quoteaddr(self.lastAddress))
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/mail/smtp.py", line 179, in quoteaddr
	    res = email.utils.parseaddr(addr)
	  File "/opt/buildbot/sandbox/lib/python2.7/email/utils.py", line 214, in parseaddr
	    addrs = _AddressList(addr).addresslist
	  File "/opt/buildbot/sandbox/lib/python2.7/email/_parseaddr.py", line 457, in __init__
	    self.addresslist = self.getaddrlist()
	  File "/opt/buildbot/sandbox/lib/python2.7/email/_parseaddr.py", line 217, in getaddrlist
	    while self.pos < len(self.field):
	exceptions.TypeError: object of type 'module' has no len()
	
2017-09-19 20:08:39-0400 [ESMTPSender,client] SMTP Client retrying server. Retry: 1
2017-09-19 20:08:40-0400 [ESMTPSender,client] Unhandled Error
	Traceback (most recent call last):
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/python/log.py", line 103, in callWithLogger
	    return callWithContext({"system": lp}, func, *args, **kw)
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/python/log.py", line 86, in callWithContext
	    return context.call({ILogContext: newCtx}, func, *args, **kw)
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/python/context.py", line 122, in callWithContext
	    return self.currentContext().callWithContext(ctx, func, *args, **kw)
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/python/context.py", line 85, in callWithContext
	    return func(*args,**kw)
	--- <exception caught here> ---
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/internet/posixbase.py", line 597, in _doReadOrWrite
	    why = selectable.doRead()
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/internet/tcp.py", line 208, in doRead
	    return self._dataReceived(data)
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/internet/tcp.py", line 214, in _dataReceived
	    rval = self.protocol.dataReceived(data)
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/protocols/basic.py", line 571, in dataReceived
	    why = self.lineReceived(line)
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/mail/smtp.py", line 995, in lineReceived
	    why = self._okresponse(self.code, b'\n'.join(self.resp))
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/mail/smtp.py", line 1044, in smtpState_to
	    return self.smtpState_toOrData(0, b'')
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/mail/smtp.py", line 1062, in smtpState_toOrData
	    self.sendLine(b'RCPT TO:' + quoteaddr(self.lastAddress))
	  File "/opt/buildbot/sandbox/lib/python2.7/site-packages/twisted/mail/smtp.py", line 179, in quoteaddr
	    res = email.utils.parseaddr(addr)
	  File "/opt/buildbot/sandbox/lib/python2.7/email/utils.py", line 214, in parseaddr
	    addrs = _AddressList(addr).addresslist
	  File "/opt/buildbot/sandbox/lib/python2.7/email/_parseaddr.py", line 457, in __init__
	    self.addresslist = self.getaddrlist()
	  File "/opt/buildbot/sandbox/lib/python2.7/email/_parseaddr.py", line 217, in getaddrlist
	    while self.pos < len(self.field):
	exceptions.TypeError: object of type 'module' has no len()
	
2017-09-19 20:08:40-0400 [-] Unhandled error in Deferred:
2017-09-19 20:08:40-0400 [-] Unhandled Error
	Traceback (most recent call last):
	Failure: exceptions.TypeError: object of type 'module' has no len()
	
2017-09-19 20:08:40-0400 [-] Stopping factory <twisted.mail.smtp.ESMTPSenderFactory instance at 0x7f6098103cf8>



Discussion:
This is a known problem in Twisted which buildbot uses to send mail.  Can you work around this by installing a newer version of Twisted from my branch:

```
python -m pip install --upgrade git+https://github.com/twisted/twisted@9250-rodrigc-mail
```
Your branch solves the problem for me.  Thanks!
Great, I'm happy to hear that.  I hope to get this branch merged to Twisted and part of an official release.
Duplicate of https://github.com/buildbot/buildbot/issues/3319

Resolving patch:
diff --git a/master/setup.py b/master/setup.py
--- a/master/setup.py
+++ b/master/setup.py
@@ -453,7 +453,7 @@ def define_plugin_entries(groups):
             raise RuntimeError(VERSION_MSG)
 
 if sys.version_info[0] >= 3:
-    twisted_ver = ">= 17.5.0"
+    twisted_ver = ">= 17.9.0"
 else:
     twisted_ver = ">= 14.0.1"
 autobahn_ver = ">= 0.16.0"
diff --git a/worker/setup.py b/worker/setup.py
--- a/worker/setup.py
+++ b/worker/setup.py
@@ -128,7 +128,7 @@ def make_release_tree(self, base_dir, files):
     setup_args['zip_safe'] = False
 
 if sys.version_info[0] >= 3:
-    twisted_ver = ">= 17.5.0"
+    twisted_ver = ">= 17.9.0"
 else:
     twisted_ver = ">= 10.2.0"
 


Test patch: