For future googlers: it turns out in my case the call to .starttls() was not needed: I removed it and everything worked. Dunno why I was there in the first place, the original code was written by somebody else.