In my model I have
file = fields.Binary(string='File', store=False, required=True)
How can I send it by mail? Y would like to be able to chose any custom email to send to.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
In my model I have
file = fields.Binary(string='File', store=False, required=True)
How can I send it by mail? Y would like to be able to chose any custom email to send to.
Try this code,
def send_mail_func(self)
email_template = self.env.ref('module1.test_email_template')
attachment = {
'name': str(self.file_name),
'datas': self.binary_field_name
datas_fname': self.file_name,
'res_model': 'model_name',
'type': 'binary'
}
id = self.env['ir.attachment'].create(attachment)
email_template.attachment_ids = [(4, ir_id.id)]
email_template.send_mail(self.id, raise_exception=False, force_send=True)
Hey thanks, I am on the right way. I need to see the compose mail form though so I can manually put the mail_to: and the body of the message. Right now the mails stay as not sent so I have to go to settings->mail and resend them with the correct mail_to:
Also I see that the attachments are not being deleted after the mail is sent. The template has <field name="auto_delete" eval="True"/>
Hi Magen,
After sending a mail, use 'email_template.attachment_ids = [(3, ir_id.id)]' to unlink the attachment.
Where can I execute the code after sending the mail since I use the 'email_compose_message_wizard_form' instead of sending it directly with 'send_mail'
Also in my question I mention that in the 'compose_message_wizard' I want to specify custom email to send to not a user. I still can't figure out this one.
Ok i made it work like that [EDIT: it does not attach correctly the file]
def action_send_mail(self):
self.ensure_one()
attachment = {
'name': ("%s" %self.filename),
'datas': self.get_file_data(),
'datas_fname': self.filename,
'res_model': 'music_audiofile',
'type': 'binary'
}
id = self.env['ir.attachment'].create(attachment)
ir_model_data = self.env['ir.model.data']
try:
template_id = ir_model_data.get_object_reference('music', 'email_template_music_audiofile')[1]
except ValueError:
template_id = False
try:
compose_form_id = ir_model_data.get_object_reference('mail', 'email_compose_message_wizard_form')[1]
except ValueError:
compose_form_id = False
ctx = dict()
ctx.update({
'default_model': 'music.audiofile',
'default_res_id': self.ids[0],
'default_use_template': bool(template_id),
'default_template_id': template_id,
'default_composition_mode': 'comment',
'mark_so_as_sent': True,
'attachment_ids': [(4, id.id)],
})
return {
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'mail.compose.message',
'views': [(compose_form_id, 'form')],
'view_id': compose_form_id,
'target': 'new',
'context': ctx,
}.
So what is wrong with this approach. And I cannot figure out how to enter manually the Mail To: instead of choosing from the list of users as s.Do I have to override the email_compose_message_wizard_form or something like that?
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
Binary field as attachment in mail
Đã xử lý
|
|
5
thg 1 23
|
16754 | |
|
1
thg 8 24
|
1990 | ||
|
1
thg 3 15
|
7077 | ||
|
0
thg 11 21
|
3217 | ||
|
2
thg 7 20
|
27866 |