|
@@ -10,6 +10,7 @@ from __future__ import absolute_import
|
|
|
|
|
|
import sys
|
|
import sys
|
|
import smtplib
|
|
import smtplib
|
|
|
|
+import socket
|
|
import traceback
|
|
import traceback
|
|
import warnings
|
|
import warnings
|
|
|
|
|
|
@@ -20,6 +21,15 @@ from .imports import symbol_by_name
|
|
|
|
|
|
supports_timeout = sys.version_info >= (2, 6)
|
|
supports_timeout = sys.version_info >= (2, 6)
|
|
|
|
|
|
|
|
+_local_hostname = None
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def get_local_hostname():
|
|
|
|
+ global _local_hostname
|
|
|
|
+ if _local_hostname is None:
|
|
|
|
+ _local_hostname = socket.getfqdn()
|
|
|
|
+ return _local_hostname
|
|
|
|
+
|
|
|
|
|
|
class SendmailWarning(UserWarning):
|
|
class SendmailWarning(UserWarning):
|
|
"""Problem happened while sending the email message."""
|
|
"""Problem happened while sending the email message."""
|
|
@@ -82,7 +92,8 @@ class Mailer(object):
|
|
|
|
|
|
def _send(self, message, **kwargs):
|
|
def _send(self, message, **kwargs):
|
|
Client = smtplib.SMTP_SSL if self.use_ssl else smtplib.SMTP
|
|
Client = smtplib.SMTP_SSL if self.use_ssl else smtplib.SMTP
|
|
- client = Client(self.host, self.port, **kwargs)
|
|
|
|
|
|
+ client = Client(self.host, self.port,
|
|
|
|
+ local_hostname=get_local_hostname(), **kwargs)
|
|
|
|
|
|
if self.use_tls:
|
|
if self.use_tls:
|
|
client.ehlo()
|
|
client.ehlo()
|
|
@@ -93,7 +104,10 @@ class Mailer(object):
|
|
client.login(self.user, self.password)
|
|
client.login(self.user, self.password)
|
|
|
|
|
|
client.sendmail(message.sender, message.to, str(message))
|
|
client.sendmail(message.sender, message.to, str(message))
|
|
- client.quit()
|
|
|
|
|
|
+ try:
|
|
|
|
+ client.quit()
|
|
|
|
+ except socket.sslerror:
|
|
|
|
+ client.close()
|
|
|
|
|
|
|
|
|
|
class ErrorMail(object):
|
|
class ErrorMail(object):
|