Parcourir la source

fixes in outgoing email connection error handling

version-14
Anand Doshi il y a 13 ans
Parent
révision
979e64187e
3 fichiers modifiés avec 40 ajouts et 11 suppressions
  1. +3
    -0
      py/webnotes/__init__.py
  2. +2
    -1
      py/webnotes/handler.py
  3. +35
    -10
      py/webnotes/utils/email_lib/send.py

+ 3
- 0
py/webnotes/__init__.py Voir le fichier

@@ -61,6 +61,9 @@ class AuthenticationError(Exception):


class PermissionError(Exception): class PermissionError(Exception):
pass pass
class OutgoingEmailError(ValidationError):
pass


class UnknownDomainError(Exception): class UnknownDomainError(Exception):
def __init__(self, value): def __init__(self, value):


+ 2
- 1
py/webnotes/handler.py Voir le fichier

@@ -182,7 +182,8 @@ def handle():
# login executed in webnotes.auth # login executed in webnotes.auth
try: try:
execute_cmd(cmd) execute_cmd(cmd)
except webnotes.ValidationError:
except webnotes.ValidationError, e:
webnotes.errprint(e)
webnotes.conn.rollback() webnotes.conn.rollback()
except: except:
webnotes.errprint(webnotes.utils.getTraceback()) webnotes.errprint(webnotes.utils.getTraceback())


+ 35
- 10
py/webnotes/utils/email_lib/send.py Voir le fichier

@@ -218,7 +218,7 @@ class EMail:
self.make_msg() self.make_msg()
sess = self.smtp_connect() sess = self.smtp_connect()
sess.sendmail(self.sender, self.recipients, self.msg_root.as_string()) sess.sendmail(self.sender, self.recipients, self.msg_root.as_string())
try: try:
@@ -229,23 +229,48 @@ class EMail:


def smtp_connect(self): def smtp_connect(self):
""" """
Gets a smtp connection
Gets a smtp connection and handles errors
""" """
from webnotes.utils import cint from webnotes.utils import cint
import smtplib import smtplib
sess = smtplib.SMTP(self.server, cint(self.port) or None)
import _socket
if self.use_ssl:
sess.ehlo()
sess.starttls()
sess.ehlo()
# check if email server specified
if not self.server:
err_msg = 'Outgoing Mail Server not specified'
webnotes.msgprint(err_msg)
raise webnotes.OutgoingEmailError, err_msg
try:
sess = smtplib.SMTP(self.server, cint(self.port) or None)
if not sess:
err_msg = 'Could not connect to outgoing email server'
webnotes.msgprint(err_msg)
raise webnotes.OutgoingEmailError, err_msg
if self.use_ssl:
sess.ehlo()
sess.starttls()
sess.ehlo()
if self.login and self.password:
ret = sess.login(self.login, self.password) ret = sess.login(self.login, self.password)


# check if logged correctly # check if logged correctly
if ret[0]!=235: if ret[0]!=235:
msgprint(ret[1]) msgprint(ret[1])
raise Exception
raise webnotes.OutgoingEmailError, ret[1]


return sess
return sess
except _socket.error, e:
# Invalid mail server -- due to refusing connection
webnotes.msgprint('Invalid Outgoing Mail Server or Port. Please rectify and try again.')
raise webnotes.OutgoingEmailError, e
except smtplib.SMTPAuthenticationError, e:
webnotes.msgprint('Invalid Login Id or Mail Password. Please rectify and try again.')
raise webnotes.OutgoingEmailError, e
except smtplib.SMTPException, e:
webnotes.msgprint('There is something wrong with your Outgoing Mail Settings. \
Please contact us at support@erpnext.com')
raise webnotes.OutgoingEmailError, e

Chargement…
Annuler
Enregistrer