瀏覽代碼

fixes in outgoing email connection error handling

version-14
Anand Doshi 13 年之前
父節點
當前提交
979e64187e
共有 3 個檔案被更改,包括 40 行新增11 行删除
  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 查看文件

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

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

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


+ 2
- 1
py/webnotes/handler.py 查看文件

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


+ 35
- 10
py/webnotes/utils/email_lib/send.py 查看文件

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

def smtp_connect(self):
"""
Gets a smtp connection
Gets a smtp connection and handles errors
"""
from webnotes.utils import cint
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)

# check if logged correctly
if ret[0]!=235:
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

Loading…
取消
儲存