[IMP] email: improvment in email_send method
bzr revid: rha@tinyerp.com-20110322133725-3dfx8pvx3dy41mgk
This commit is contained in:
parent
2fe7c51e36
commit
5bca2b6f1c
|
@ -19,7 +19,6 @@
|
|||
#
|
||||
##############################################################################
|
||||
|
||||
#import email_smtp_server
|
||||
import email_message
|
||||
import email_thread
|
||||
import res_partner
|
||||
|
|
|
@ -83,7 +83,7 @@ class email_message_common(osv.osv_memory):
|
|||
'priority':fields.integer('Priority'),
|
||||
'body': fields.text('Description', translate=True),
|
||||
'body_html': fields.text('HTML', help="Contains HTML version of email"),
|
||||
'smtp_server_id':fields.many2one('ir.mail.server', 'SMTP Server'),
|
||||
'smtp_server_id':fields.many2one('ir.mail_server', 'SMTP Server'),
|
||||
}
|
||||
_rec_name='subject'
|
||||
|
||||
|
@ -227,7 +227,7 @@ class email_message(osv.osv):
|
|||
'debug': debug,
|
||||
'history': True,
|
||||
'smtp_server_id': smtp_server_id,
|
||||
'state': 'waiting',
|
||||
'state': 'outgoing',
|
||||
}
|
||||
email_msg_id = self.create(cr, uid, msg_vals, context)
|
||||
if attach:
|
||||
|
@ -247,7 +247,7 @@ class email_message(osv.osv):
|
|||
return email_msg_id
|
||||
|
||||
def process_retry(self, cr, uid, ids, context=None):
|
||||
return self.write(cr, uid, ids, {'state':'waiting'}, context)
|
||||
return self.write(cr, uid, ids, {'state':'outgoing'}, context)
|
||||
|
||||
def process_email_queue(self, cr, uid, ids=None, context=None):
|
||||
if ids is None:
|
||||
|
@ -255,13 +255,13 @@ class email_message(osv.osv):
|
|||
if context is None:
|
||||
context = {}
|
||||
attachment_obj = self.pool.get('ir.attachment')
|
||||
smtp_server_obj = self.pool.get('ir.mail.server')
|
||||
smtp_server_obj = self.pool.get('ir.mail_server')
|
||||
if not ids:
|
||||
filters = [('state', '=', 'outgoing')]
|
||||
if 'filters' in context:
|
||||
filters.extend(context['filters'])
|
||||
ids = self.search(cr, uid, filters, context=context)
|
||||
self.write(cr, uid, ids, {'state':'sending'}, context)
|
||||
self.write(cr, uid, ids, {'state':'outgoing'}, context)
|
||||
for message in self.browse(cr, uid, ids, context):
|
||||
try:
|
||||
attachments = []
|
||||
|
@ -269,7 +269,7 @@ class email_message(osv.osv):
|
|||
attachments.append((attach.datas_fname ,base64.b64decode(attach.datas)))
|
||||
smtp_server = message.smtp_server_id
|
||||
if not smtp_server:
|
||||
smtp_ids = smtp_server_obj.search(cr, uid, [('default','=',True)])
|
||||
smtp_ids = smtp_server_obj.search(cr, uid, [])
|
||||
if smtp_ids:
|
||||
smtp_server = smtp_server_obj.browse(cr, uid, smtp_ids, context)[0]
|
||||
res = self.send_email(cr, uid, ids, auto_commit=True, context=context)
|
||||
|
@ -283,6 +283,22 @@ class email_message(osv.osv):
|
|||
self.write(cr, uid, [message.id], {'state':'exception'}, context)
|
||||
return ids
|
||||
|
||||
def send_email(self, cr, uid, ids, auto_commit=False, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
smtp_server_obj = self.pool.get('ir.mail_server')
|
||||
for message in self.browse(cr, uid, ids, context):
|
||||
try:
|
||||
if message.state in ['outgoing', 'exception']:
|
||||
msg_id = smtp_server_obj.send_email(cr, uid, message.email_from, message.email_to, message.body, id=message.smtp_server_id, subject=message.subject)
|
||||
else:
|
||||
raise osv.except_osv(_('Error !'), _('Message is not in outgoing state!'))
|
||||
except Exception, error:
|
||||
logger = netsvc.Logger()
|
||||
logger.notifyChannel("email-template", netsvc.LOG_ERROR, _("Sending of Mail %s failed. Probable Reason:Could not login to server\nError: %s") % (message.id, error))
|
||||
self.write(cr, uid, [message.id], {'state':'exception'}, context)
|
||||
return False
|
||||
return True
|
||||
# OLD Code.
|
||||
# def send_all_mail(self, cr, uid, ids=None, context=None):
|
||||
# if ids is None:
|
||||
|
|
|
@ -218,7 +218,7 @@ class email_compose_message(osv.osv_memory):
|
|||
references = mail.references and mail.references + "," + mail.message_id or mail.message_id
|
||||
else:
|
||||
message_id = mail.message_id
|
||||
email_id = email_message_pool.schedule_with_attach(cr, uid, mail.email_from, mail.email_to, mail.name, mail.description,
|
||||
email_id = email_message_pool.schedule_with_attach(cr, uid, mail.email_from, mail.email_to, mail.subject, mail.body,
|
||||
model=mail.model, email_cc=mail.email_cc, email_bcc=mail.email_bcc, reply_to=mail.reply_to,
|
||||
attach=attachment, message_id=message_id, references=references, openobject_id=int(mail.res_id), debug=mail.debug,
|
||||
subtype=mail.sub_type, x_headers=mail.headers, priority=mail.priority, smtp_server_id=mail.smtp_server_id and mail.smtp_server_id.id, context=context)
|
||||
|
|
|
@ -18,12 +18,12 @@
|
|||
<field name="email_cc" colspan="4"/>
|
||||
<field name="email_bcc" colspan="4"/>
|
||||
<field name="reply_to" colspan="4"/>
|
||||
<field name="name" colspan="4" widget="char" size="512"/>
|
||||
<field name="subject" colspan="4" widget="char" size="512"/>
|
||||
</group>
|
||||
<separator string="" colspan="4"/>
|
||||
<notebook colspan="4">
|
||||
<page string="Body">
|
||||
<field name="description" colspan="4" nolabel="1"/>
|
||||
<field name="body" colspan="4" nolabel="1"/>
|
||||
</page>
|
||||
<page string="Attachments">
|
||||
<label string="Add here all attachments of the current document you want to include in the Email." colspan="4"/>
|
||||
|
|
|
@ -44,8 +44,8 @@ class email_compose_message(osv.osv_memory):
|
|||
result.update({
|
||||
'template_id' : template.id,
|
||||
'smtp_server_id' : template.smtp_server_id.id,
|
||||
'description' : _get_template_value('description') or False,
|
||||
'name' : _get_template_value('subject') or False,
|
||||
'body' : _get_template_value('description') or False,
|
||||
'subject' : _get_template_value('subject') or False,
|
||||
'attachment_ids' : template_pool.read(cr, uid, template.id, ['attachment_ids'])['attachment_ids'] or [],
|
||||
'res_id' : res_id or False,
|
||||
'email_to' : _get_template_value('email_to') or False,
|
||||
|
@ -92,11 +92,11 @@ class email_compose_message(osv.osv_memory):
|
|||
if 'email_bcc' in fields:
|
||||
result.update({'email_bcc' : vals.get('email_bcc', False)})
|
||||
|
||||
if 'name' in fields:
|
||||
result.update({'name' : vals.get('name', False)})
|
||||
if 'subject' in fields:
|
||||
result.update({'subject' : vals.get('name', False)})
|
||||
|
||||
if 'description' in fields:
|
||||
result.update({'description' : vals.get('description', False)})
|
||||
if 'body' in fields:
|
||||
result.update({'body' : vals.get('description', False)})
|
||||
|
||||
if 'reply_to' in fields:
|
||||
result.update({'reply_to' : vals.get('reply_to', False)})
|
||||
|
|
|
@ -95,11 +95,11 @@ class email_template_preview(osv.osv_memory):
|
|||
elif template.track_campaign_item:
|
||||
vals['message_id'] = tools.misc.generate_tracking_message_id(res_id)
|
||||
vals['subject'] = self.get_template_value(cr, uid, template.subject, model, res_id, context)
|
||||
description = self.get_template_value(cr, uid, template.description, model, res_id, context) or ''
|
||||
description = self.get_template_value(cr, uid, template.body, model, res_id, context) or ''
|
||||
if template.user_signature:
|
||||
signature = self.pool.get('res.users').browse(cr, uid, uid, context).signature
|
||||
description += '\n' + signature
|
||||
vals['description'] = description
|
||||
vals['body'] = description
|
||||
vals['report_name'] = self.get_template_value(cr, uid, template.report_name, model, res_id, context)
|
||||
return {'value':vals}
|
||||
|
||||
|
|
|
@ -91,8 +91,8 @@ class email_template_send_wizard(osv.osv_memory):
|
|||
if 'subject' in fields:
|
||||
result['subject'] = _get_template_value('subject')
|
||||
|
||||
if 'description' in fields:
|
||||
result['description'] = _get_template_value('description')
|
||||
if 'body' in fields:
|
||||
result['body'] = _get_template_value('description')
|
||||
|
||||
#if 'body_html' in fields:
|
||||
# result['body_html'] = _get_template_value('body_html')
|
||||
|
|
Loading…
Reference in New Issue