1
votes

I am trying with the following code which functions as sending mail

def send_mail_employee(self,cr,uid,ids,context=None):
record_obj = self.browse(cr,uid,ids,context=context)
ir_model_data = self.pool.get('ir.model.data')
template_obj = self.pool.get('email.template')
attch_ids = []
for rec in record_obj:
if not rec.name.work_email:
raise osv.except_osv(_('Warning!'), _('Please configure employee email address!'))
else:
for attch in rec.attchment_lines:
attch_ids.append(attch.id)
template_id = ir_model_data.get_object_reference(cr,uid,'registers', 'email_template_register_courier')[1]
self.pool.get('email.template').write(cr,uid,template_id,{'attachment_ids':[(6,0,attch_ids)]})              self.pool.get('email.template').send_mail(cr,uid,template_id,rec.id,force_send=True,context=context)
return True

The problem i find is after attaching the attachment file and sending it, the attachment doesn't appear with its name or file type in the mail

1

1 Answers

0
votes

Shravya Shetty,

It will take of the attachment which you are attaching rec.attchment_lines: you have to make sure you assigning right name to the attachment, and Odoo attachment does not store the type of the file, it just store extension of the file in names so you might have to extract the type by using re or string split to get extension.

Bests,