[FIX]: fix a problem of sending email if we are using sendmail tool with server action

it was coded in such way that we can not send email without --email-from parameter, but in case if we are using sendmail,
we can user user's emails or auto generated email to define email-from

bzr revid: mga@openerp.com-20110801114543-hi12oqciol8a62pc
This commit is contained in:
Mantavya Gajjar
2011-08-01 17:15:43 +05:30
parent 153cd2c6ad
commit 992c7bc76e
+19 -11
View File
@@ -32,6 +32,7 @@ import copy
import os
from xml import dom
from report.report_sxw import report_sxw, report_rml
from socket import gethostname
class actions(osv.osv):
_name = 'ir.actions.actions'
@@ -598,16 +599,18 @@ class actions_server(osv.osv):
logger = logging.getLogger(self._name)
if context is None:
context = {}
user = self.pool.get('res.users').browse(cr, uid, uid)
for action in self.browse(cr, uid, ids, context):
obj_pool = self.pool.get(action.model_id.model)
obj = obj_pool.browse(cr, uid, context['active_id'], context=context)
cxt = {
'context': dict(context), # copy context to prevent side-effects of eval
'object': obj,
'context':dict(context), # copy context to prevent side-effects of eval
'object':obj,
'time':time,
'cr': cr,
'pool' : self.pool,
'uid' : uid
'cr':cr,
'pool':self.pool,
'uid':uid,
'user':user
}
expr = eval(str(action.condition), cxt)
if not expr:
@@ -629,13 +632,14 @@ class actions_server(osv.osv):
'uid': uid,
'object':obj,
'obj': obj,
'user':user
}
eval(action.code, localdict, mode="exec", nocopy=True) # nocopy allows to return 'action'
if 'action' in localdict:
return localdict['action']
if action.state == 'email':
user = config['email_from']
email_from = config['email_from']
address = str(action.email)
try:
address = eval(str(action.email), cxt)
@@ -643,16 +647,20 @@ class actions_server(osv.osv):
pass
if not address:
logger.info('Partner Email address not Specified!')
logger.info('Partner email address not specified!')
continue
if not user:
logger.info('Email-From address not Specified at server!')
raise osv.except_osv(_('Error'), _("Please specify server option --email-from !"))
if not email_from:
logger.info('Email from address not specify at server option --email-from !')
if user.user_email:
email_from = user.user_email
else:
email_from = "%s@%s" % (user.login, gethostname())
subject = self.merge_message(cr, uid, action.subject, action, context)
body = self.merge_message(cr, uid, action.message, action, context)
if tools.email_send(user, [address], subject, body, debug=False, subtype='html') == True:
if tools.email_send(email_from, [address], subject, body, debug=False, subtype='html') == True:
logger.info('Email successfully sent to: %s', address)
else:
logger.warning('Failed to send email to: %s', address)