Can't make email connection doing a Mail Merge in Writer

I’m on Windows 10, LO 5.4.1.2

I’m trying to do an email mail merge from writer but the test settings option always fails.

The mail settings I’m using are correct (servername, username & password) they are same as my email client

Error:

LibreOffice could not connect to the outgoing mail server. Check your system's settings and the settings in LibreOffice. Check the server name, the port and the secure connections settings
--
<class 'smtplib.SMTPServerDisconnected'>: Connection unexpectedly closed: [WinError 10054] 
An existing connection was forcibly closed by the remote host, traceback follows
  File "C:\Program Files (x86)\LibreOffice 5\program\mailmerge.py", line 107, in connect self.server = smtplib.SMTP(server, port,timeout=tout)
  File "C:\Program Files (x86)\LibreOffice 5\program\python-core-3.5.0\lib\smtplib.py", line 251, in __init__
    (code, msg) = self.connect(host, port)
  File "C:\Program Files (x86)\LibreOffice 5\program\python-core-3.5.0\lib\smtplib.py", line 338, in connect
    (code, msg) = self.getreply()
  File "C:\Program Files (x86)\LibreOffice 5\program\python-core-3.5.0\lib\smtplib.py", line 391, in getreply
    + str(e))

When I try Port 587 as suggested by earlier threads I get:

LibreOffice could not connect to the outgoing mail server. Check your system’s settings and the settings in LibreOffice. Check the server name, the port and the secure connections settings

<class ‘RuntimeError’>: No SSL support included in this Python, traceback follows
File “C:\Program Files (x86)\LibreOffice 5\program\mailmerge.py”, line 121, in connect
self.server.starttls()
File “C:\Program Files (x86)\LibreOffice 5\program\python-core-3.5.0\lib\smtplib.py”, line 756, in starttls
raise RuntimeError(“No SSL support included in this Python”)

Did you also check the port setting in LO config?

Yes, port 465

Just setup an new gmail account for this but still no luck, getting this:

LibreOffice could not connect to the outgoing mail server. Check your system’s settings and the settings in LibreOffice. Check the server name, the port and the secure connections settings

<class ‘smtplib.SMTPServerDisconnected’>: Connection unexpectedly closed, traceback follows
File “C:\Program Files (x86)\LibreOffice 5\program\mailmerge.py”, line 107, in connect
self.server = smtplib.SMTP(server, port,timeout=

I’ve just taken screenshots of my setting but I can’t upload them here!!!

Pasted in another error in original message as this comment box doesn’t give enough characters!

I think I’ve finally got reliable connection to Yahoo POP server (outbound.att.net, port 465). The usual error message when I did the test from Tools->Options->LibreOffice Writer->MailMerge Email was “starttls extension not supported by server”. I made 2 changes to the python code in Linux at /usr/lib/libreoffice/program/mailmerge.py. I am on Ubuntu 16.04, Libre version is 5.1.6.2.

First made the change suggested in Why won't mail merge connect to my outgoing email server?

from
self.server = smtplib.SMTP(server, port,timeout=tout)
to
self.server = smtplib.SMTP_SSL(server, port,timeout=tout)

which helped sometimes but still connection usually did not work.

Second, I see Python docs http://docs.python.org/3/library/smtplib.html on SMTP_SSL, it says starttls is not necessary in an already established SSL connection. So I commented out the offending starttls lines. The code in mailmerge.py now looks like:

self.server = smtplib.SMTP_SSL(server, port,timeout=tout)

            #stderr not available for us under windows, but
            #set_debuglevel outputs there, and so throw
            #an exception under windows on debugging mode
            #with this enabled
            if dbg and os.name != 'nt':
                    self.server.set_debuglevel(1)

            connectiontype = xConnectionContext.getValueByName("ConnectionType")
            if dbg:
                    print("ConnectionType: " + connectiontype, file=dbgout)
            if connectiontype.upper() == 'SSL':
            #self.server.ehlo()
            #self.server.starttls()
                    self.server.ehlo()

This is around line 120. Connection test and mail merge from Libre Writer seems to work now.

These changes may be erased and have to be redone if Libre does an update.
Hope this helps someone.

With the modifications proposed by wb8nbs the connection is always a secure one using SSL/TLS. To support both secure and non secure connections we need to call either smtplib.SMTP or smtplib.SMTP_SSL depending on the value of connectiontype.

I’ve modified the file mailmerge.py (version LO 6.0.7 on Ubuntu) accordingly. Lines 105 to 124 become :

	if dbg:
		print("Timeout: " + str(tout), file=dbgout)
	
	# Modifications by erpiu: choose SMTP or SMTP_SSL depending on connectiontype
	connectiontype = xConnectionContext.getValueByName("ConnectionType")
	if dbg:
		print("ConnectionType: " + connectiontype, file=dbgout)
	if connectiontype.upper() == 'SSL':
		self.server = smtplib.SMTP_SSL(server, port,timeout=tout)
		# Following calls are not necessary when using SMTP_SSL
		#self.server.ehlo()
		#self.server.starttls()
		#self.server.ehlo()
	else:
		self.server = smtplib.SMTP(server, port,timeout=tout)
		
	#stderr not available for us under windows, but
	#set_debuglevel outputs there, and so throw
	#an exception under windows on debugging mode
	#with this enabled
	# End of modifications by erpiu
		
	if dbg and os.name != 'nt':
		self.server.set_debuglevel(1)

	user = xAuthenticator.getUserName()

With those modifications we can establish either a secure connection “by port” (ie from the very beginning) with an SMTP server, typically using the port 465 and SSL/TLS, or a non secure connection, for instance on the port 25 or 587.

Notice that, as it is programmed, we cannot switch from a non secure connection to a secure one using STARTTLS, which is another method to establish a secure connection (this method is often unsuitably referred to as “TLS” instead of “STARTTLS”).

I hope all this helps.