diff --git a/addons/email_template/email_template.py b/addons/email_template/email_template.py
index 37b38774a7d..9190bd17e2b 100644
--- a/addons/email_template/email_template.py
+++ b/addons/email_template/email_template.py
@@ -108,7 +108,8 @@ class email_template(osv.osv):
'enforce_from_account':fields.many2one(
'email_template.account',
string="Enforce From Account",
- help="Emails will be sent only from this account."),
+ help="Emails will be sent only from this account(which are approved).",
+ domain=[('state','=','approved')]),
'from_email' : fields.related('enforce_from_account', 'email_id',
type='char', string='From',),
'def_to':fields.char(
@@ -580,8 +581,8 @@ class email_template(osv.osv):
context)
print 'Sending', mailbox_id
- self.pool.get('email_template.mailbox').send_this_mail(cursor, user, [mailbox_id], context)
return mailbox_id
+
def generate_mail(self,
cursor,
@@ -595,6 +596,7 @@ class email_template(osv.osv):
if not template:
raise Exception("The requested template could not be loaded")
print 'loaded', record_ids
+ result = True
for record_id in record_ids:
mailbox_id = self._generate_mailbox_item_from_template(
cursor,
@@ -625,7 +627,9 @@ class email_template(osv.osv):
{'folder':'outbox'},
context=context
)
- return True
+ # TODO : manage return value of all the records
+ result = self.pool.get('email_template.mailbox').send_this_mail(cursor, user, [mailbox_id], context)
+ return result
email_template()
@@ -641,7 +645,7 @@ class email_template_preview(osv.osv_memory):
if 'template_id' in context.keys():
ref_obj_id = self.pool.get('email.template').read(cr, uid, context['template_id'], ['object_name'], context)
ref_obj_name = self.pool.get('ir.model').read(cr, uid, ref_obj_id['object_name'][0], ['model'], context)['model']
- ref_obj_ids = self.pool.get(ref_obj_name).search(cr, uid, [], context=context)
+ ref_obj_ids = self.pool.get(ref_obj_name).search(cr, uid, [], 0, 20, 'id desc', context=context)
ref_obj_recs = self.pool.get(ref_obj_name).name_get(cr, uid, ref_obj_ids, context)
return ref_obj_recs
diff --git a/addons/email_template/email_template_account.py b/addons/email_template/email_template_account.py
index 0bcf3c3d099..52cff384ec4 100644
--- a/addons/email_template/email_template_account.py
+++ b/addons/email_template/email_template_account.py
@@ -266,7 +266,7 @@ class email_template_account(osv.osv):
return result
def send_mail(self, cr, uid, ids, addresses, subject='', body=None, payload=None, context=None):
- #TODO: Replace all this crap with a single email object
+ #TODO: Replace all this with a single email object
if body is None:
body = {}
if payload is None:
@@ -320,19 +320,20 @@ class email_template_account(osv.osv):
msg.attach(part)
except Exception, error:
logger.notifyChannel(_("Email Template"), netsvc.LOG_ERROR, _("Mail from Account %s failed. Probable Reason:MIME Error\nDescription: %s") % (id, error))
- return error
+ return {'error_msg': "Server Send Error\nDescription: %s"%error}
try:
#print msg['From'],toadds
serv.sendmail(msg['From'], addresses_l['all'], msg.as_string())
except Exception, error:
logger.notifyChannel(_("Email Template"), netsvc.LOG_ERROR, _("Mail from Account %s failed. Probable Reason:Server Send Error\nDescription: %s") % (id, error))
- return error
+ return {'error_msg': "Server Send Error\nDescription: %s"%error}
#The mail sending is complete
serv.close()
logger.notifyChannel(_("Email Template"), netsvc.LOG_INFO, _("Mail from Account %s successfully Sent.") % (id))
return True
else:
logger.notifyChannel(_("Email Template"), netsvc.LOG_ERROR, _("Mail from Account %s failed. Probable Reason:Account not approved") % id)
+ return {'error_msg':"Mail from Account %s failed. Probable Reason:Account not approved"% id}
def extracttime(self, time_as_string):
"""
@@ -394,7 +395,6 @@ class email_template_account(osv.osv):
return date_as_date
def send_receive(self, cr, uid, ids, context=None):
- self.get_mails(cr, uid, ids, context)
for id in ids:
ctx = context.copy()
ctx['filters'] = [('account_id', '=', id)]
diff --git a/addons/email_template/email_template_mailbox.py b/addons/email_template/email_template_mailbox.py
index fe9ca334d21..b89a9aeda26 100644
--- a/addons/email_template/email_template_mailbox.py
+++ b/addons/email_template/email_template_mailbox.py
@@ -56,18 +56,19 @@ class email_template_mailbox(osv.osv):
values['subject'] or u'',
{'text':values.get('body_text', u'') or u'', 'html':values.get('body_html', u'') or u''},
payload=payload, context=context)
-
if result == True:
self.write(cr, uid, id, {'folder':'sent', 'state':'na', 'date_mail':time.strftime("%Y-%m-%d %H:%M:%S")}, context)
self.historise(cr, uid, [id], "Email sent successfully", context)
else:
- self.historise(cr, uid, [id], result, context)
+ error = result['error_msg']
+ self.historise(cr, uid, [id], error, context)
+
except Exception, error:
logger = netsvc.Logger()
logger.notifyChannel(_("Power Email"), netsvc.LOG_ERROR, _("Sending of Mail %s failed. Probable Reason:Could not login to server\nError: %s") % (id, error))
self.historise(cr, uid, [id], error, context)
self.write(cr, uid, id, {'state':'na'}, context)
- return True
+ return result
def historise(self, cr, uid, ids, message='', context=None):
for id in ids:
diff --git a/addons/email_template/email_template_view.xml b/addons/email_template/email_template_view.xml
index 934a7324b07..12a24ca0934 100644
--- a/addons/email_template/email_template_view.xml
+++ b/addons/email_template/email_template_view.xml
@@ -8,33 +8,29 @@
form
-
+
Template Preview
email_template.preview