Skip to Content
Odoo Menu
  • Log ind
  • Prøv gratis
  • Apps
    Økonomi
    • Bogføring
    • Fakturering
    • Udgifter
    • Regneark (BI)
    • Dokumenter
    • e-Signatur
    Salg
    • CRM
    • Salg
    • POS Butik
    • POS Restaurant
    • Abonnementer
    • Udlejning
    Hjemmeside
    • Hjemmesidebygger
    • e-Handel
    • Blog
    • Forum
    • LiveChat
    • e-Læring
    Forsyningskæde
    • Lagerbeholdning
    • Produktion
    • PLM
    • Indkøb
    • Vedligeholdelse
    • Kvalitet
    HR
    • Medarbejdere
    • Rekruttering
    • Fravær
    • Medarbejdersamtaler
    • Anbefalinger
    • Flåde
    Marketing
    • Markedsføring på sociale medier
    • E-mailmarketing
    • SMS-marketing
    • Arrangementer
    • Automatiseret marketing
    • Spørgeundersøgelser
    Tjenester
    • Projekt
    • Timesedler
    • Udkørende Service
    • Kundeservice
    • Planlægning
    • Aftaler
    Produktivitet
    • Dialog
    • Godkendelser
    • IoT
    • VoIP
    • Vidensdeling
    • WhatsApp
    Tredjepartsapps Odoo Studio Odoo Cloud-platform
  • Brancher
    Detailhandel
    • Boghandel
    • Tøjforretning
    • Møbelforretning
    • Dagligvarebutik
    • Byggemarked
    • Legetøjsforretning
    Mad og værtsskab
    • Bar og pub
    • Restaurant
    • Fastfood
    • Gæstehus
    • Drikkevareforhandler
    • Hotel
    Ejendom
    • Ejendomsmægler
    • Arkitektfirma
    • Byggeri
    • Ejendomsadministration
    • Havearbejde
    • Boligejerforening
    Rådgivning
    • Regnskabsfirma
    • Odoo-partner
    • Marketingbureau
    • Advokatfirma
    • Rekruttering
    • Audit & certificering
    Produktion
    • Tekstil
    • Metal
    • Møbler
    • Fødevareproduktion
    • Bryggeri
    • Firmagave
    Heldbred & Fitness
    • Sportsklub
    • Optiker
    • Fitnesscenter
    • Kosmetolog
    • Apotek
    • Frisør
    Håndværk
    • Handyman
    • IT-hardware og support
    • Solenergisystemer
    • Skomager
    • Rengøringsservicer
    • VVS- og ventilationsservice
    Andet
    • Nonprofitorganisation
    • Miljøagentur
    • Udlejning af billboards
    • Fotografi
    • Cykeludlejning
    • Softwareforhandler
    Gennemse alle brancher
  • Community
    Få mere at vide
    • Tutorials
    • Dokumentation
    • Certificeringer
    • Oplæring
    • Blog
    • Podcast
    Bliv klogere
    • Udannelselsesprogram
    • Scale Up!-virksomhedsspillet
    • Besøg Odoo
    Få softwaren
    • Download
    • Sammenlign versioner
    • Udgaver
    Samarbejde
    • Github
    • Forum
    • Arrangementer
    • Oversættelser
    • Bliv partner
    • Tjenester til partnere
    • Registrér dit regnskabsfirma
    Modtag tjenester
    • Find en partner
    • Find en bogholder
    • Kontakt en rådgiver
    • Implementeringstjenester
    • Kundereferencer
    • Support
    • Opgraderinger
    Github Youtube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Få en demo
  • Prissætning
  • Hjælp

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Bogføring
  • Lager
  • PoS
  • Projekt
  • MRP
All apps
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Hjælp

Send a mail with fields.binary attached

Tilmeld

Få besked, når der er aktivitet på dette indlæg

Dette spørgsmål er blevet anmeldt
mailattachmentsendbinary
4 Besvarelser
11140 Visninger
Avatar
Magen

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.

0
Avatar
Kassér
Avatar
Priya K
Bedste svar

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)


In this code,  details with binary field is created in ir_attachment. Then  [(4, ir_id.id)] is used to link with existing record of email_template.  Finally the mail will be send with binary field.
1
Avatar
Kassér
Magen
Forfatter

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:

Magen
Forfatter

Also I see that the attachments are not being deleted after the mail is sent. The template has <field name="auto_delete" eval="True"/>

Priya K

Hi Magen,

After sending a mail, use 'email_template.attachment_ids = [(3, ir_id.id)]' to unlink the attachment.

Magen
Forfatter

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.

Avatar
Magen
Forfatter Bedste svar

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?

0
Avatar
Kassér
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Tilmeld dig
Related Posts Besvarelser Visninger Aktivitet
Binary field as attachment in mail Løst
mail invoice attachment binary
Avatar
Avatar
Avatar
Avatar
Avatar
5
jan. 23
17909
send email with multiple attachment
mail attachment
Avatar
1
aug. 24
2704
Send a mail with automatic attachment ofa binary field from a model
wizard mail attachment template binary
Avatar
1
mar. 15
7732
Automatically add all attachments to mail
mail attachment templates
Avatar
0
nov. 21
3855
Attach many files in a binary field type
attachment file binary
Avatar
Avatar
2
jul. 20
28797
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Oversættelser
Tjenester
  • Odoo.sh-hosting
  • Support
  • Opgradere
  • Individuelt tilpasset udvikling
  • Uddannelse
  • Find en bogholder
  • Find en partner
  • Bliv partner
Om os
  • Vores virksomhed
  • Brandaktiver
  • Kontakt os
  • Stillinger
  • Arrangementer
  • Podcast
  • Blog
  • Kunder
  • Juridiske dokumenter • Privatlivspolitik
  • Sikkerhedspolitik
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo er en samling open source-forretningsapps, der dækker alle dine virksomhedsbehov – lige fra CRM, e-handel og bogføring til lagerstyring, POS, projektledelse og meget mere.

Det unikke ved Odoo er, at systemet både er brugervenligt og fuldt integreret.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now