How to send email without mail template odoo 9
<p>I want to send email without any email template in odoo 9. I've set successfully outgoing &amp; incoming mail configuration.
My Scenario is the the admin mail alias as sender of email
this is my model:</p>

<pre><code>class cashadvance(osv.osv):
_name = 'comben.cashadvance'
    _order = 'create_date DESC'
    _columns = {
        'user_target'               : fields.many2one('res.users', string='User Target'),
        'mail_target'               : fields.char(string='Email Target'),
    }
</code></pre>

<p>The question is, how to send email to mail_target field using a function ? 
Help me please </p>

<p>You can send a mail directly using the <code>mail.thread</code> model, by using the following code, attached to a button.</p>

<pre><code>@api.multi
def send_mail(self):
    user_id = self.user_target.id
    body = self.message_target

    mail_details = {'subject': "Message subject",
         'body': body,
         'partner_ids': [(user_target)]
         } 

    mail = self.env['mail.thread']
    mail.message_post(type="notification", subtype="mt_comment", **mail_details)
</code></pre>

<p>Or you can just take the bull by the horn and use plain ol <code>smtplib</code> from the standard library, (but then your odoo configuration won't matter any more). This example assumes that you're using gmail. If you're not, then you have to fill in your mail server's details for this to work properly.</p>

<pre><code>@api.multi
def send_mail(self):
    import smtplib

    receivers_email = self.user_target.login

    server = smtplib.SMTP('smtp.gmail.com', 587)
    server.starttls()
    server.login("your_email_address", "password")

    message = self.message_target
    server.sendmail("your_email_address", receivers_email, message)

    server.quit()
</code></pre>

<p>Since <code>user_target</code> is related to the <code>res.users</code> field you can get the email from the <code>login</code> field</p>

python postgresql openerp