[IMP] improve help and change field name fail_mail to fail_counter and change method name of counting fail mail
from openerp.osv import fields, osv
from openerp.tools.safe_eval import safe_eval as eval
from openerp.tools.translate import _
+import openerp.tools as tools
_logger = logging.getLogger(__name__)
'email_cc': fields.char('Cc', help='Carbon copy message recipients'),
'body_html': fields.text('Rich-text Contents', help="Rich-text/HTML message"),
'headers': fields.text('Headers', copy=False),
+ 'failure_reason': fields.text('Failure Reason', help="Failure reason. This is usually the exception thrown by the email server, stored to ease the debugging of mailing issues.", readonly=1),
# Auto-detected based on create() - if 'mail_message_id' was passed then this mail is a notification
# and during unlink() we will not cascade delete the parent and its attachments
'notification': fields.boolean('Is Notification',
mail.write({'state': 'sent', 'message_id': res})
mail_sent = True
else:
- mail.write({'state': 'exception'})
+ mail.write({'state': 'exception', 'failure_reason': _('Error without exception. Probably due do sending an email without computed recipients.')})
mail_sent = False
# /!\ can't use mail.state here, as mail.refresh() will cause an error
mail.id, mail.message_id)
raise
except Exception as e:
- _logger.exception('failed sending mail.mail %s', mail.id)
- mail.write({'state': 'exception'})
+ failure_reason = tools.ustr(e)
+ _logger.exception('failed sending mail (id: %s) due to %s', mail.id, failure_reason)
+ mail.write({'state': 'exception', 'failure_reason': failure_reason})
self._postprocess_sent_message(cr, uid, mail, context=context, mail_sent=False)
if raise_exception:
if isinstance(e, AssertionError):
<page string="Attachments">
<field name="attachment_ids"/>
</page>
+ <page string="Failure Reason" attrs="{'invisible': [('state', '!=', 'exception')]}">
+ <field name="failure_reason"/>
+ </page>
</notebook>
</sheet>
</form>
<field name="res_model">mail.mail</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
- <field name="context">{'search_default_outgoing': 1}</field>
+ <field name="context">{}</field>
<field name="search_view_id" ref="view_mail_search"/>
</record>
##############################################################################
import urlparse
+import datetime
+from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
from openerp.osv import osv, fields
_inherit = 'base.config.settings'
_columns = {
+ 'fail_counter': fields.integer('Fail Mail', readonly=True),
'alias_domain': fields.char('Alias Domain',
help="If you have setup a catch-all email domain redirected to "
"the OpenERP server, enter the domain name here."),
}
+ def get_default_fail_counter(self, cr, uid, ids, context=None):
+ previous_date = datetime.datetime.now() - datetime.timedelta(days=30)
+ return {
+ 'fail_counter': self.pool.get('mail.mail').search(cr, uid, [('date', '>=', previous_date.strftime(DEFAULT_SERVER_DATETIME_FORMAT)), ('state', '=', 'exception')], count=True, context=context),
+ }
+
def get_default_alias_domain(self, cr, uid, ids, context=None):
alias_domain = self.pool.get("ir.config_parameter").get_param(cr, uid, "mail.catchall.domain", default=None, context=context)
if alias_domain is None:
<field name="model">base.config.settings</field>
<field name="inherit_id" ref="base_setup.view_general_configuration"/>
<field name="arch" type="xml">
+ <xpath expr="//button[@string='Configure outgoing email servers']" position='after'>
+ <button class="oe_inline oe_link" style="display: inline-block;" name= "%(action_view_mail_mail)d" type="action"
+ context="{'search_default_exception': 1, 'search_default_outgoing': 0}"
+ attrs="{'invisible': [('fail_counter','=',0)]}">
+ <span> -- </span>
+ <i class="fa fa-exclamation-triangle"></i> <field class="oe_inline" name="fail_counter"/>
+ <span>failed emails</span>
+ </button>
+ </xpath>
<xpath expr="//div[@name='email']" position='inside'>
<div>
<label for="alias_domain" class="oe_inline"/>
.openerp .oe_mail .oe_msg .oe_msg_content .oe_msg_body .oe_mail_cleaned {
display: none;
}
-
/* a) Indented Messages */
.openerp .oe_mail .oe_msg_indented{
mail_compose.send_mail(cr, user_raoul.id, [compose_id], {'mail_post_autofollow': True, 'mail_create_nosubscribe': True})
group_pigs.refresh()
message = group_pigs.message_ids[0]
-
+ # Test: mail_mail: notifications have been deleted
+ self.assertFalse(self.mail_mail.search(cr, uid, [('mail_message_id', '=', message.id)]),'message_send: mail.mail message should have been auto-deleted!')
# Test: mail.group: followers (c and d added by auto follow key; raoul not added by nosubscribe key)
pigs_pids = [p.id for p in group_pigs.message_follower_ids]
test_pids = [self.partner_admin_id, p_b_id, p_c_id, p_d_id]
# Test: Pigs and Bird did receive their message
test_msg_ids = self.mail_message.search(cr, uid, [], limit=2)
+ mail_ids = self.mail_mail.search(cr, uid, [('mail_message_id', '=', message2.id)])
+ mail_record_id = self.mail_mail.browse(cr, uid, mail_ids)[0]
+ self.assertTrue(mail_record_id, "'message_send: mail.mail message should have in processing mail queue'" )
+ #check mass mail state...
+ test_mail_ids = self.mail_mail.search(cr, uid, [('state', '=', 'exception')])
+ self.assertNotIn(mail_ids, test_mail_ids, 'compose wizard: Mail sending Failed!!')
self.assertIn(message1.id, test_msg_ids, 'compose wizard: Pigs did not receive its mass mailing message')
self.assertIn(message2.id, test_msg_ids, 'compose wizard: Bird did not receive its mass mailing message')