This question has been flagged
1 Reply
4258 Views

I need to send email by a scheduler.

How do I do it when I have already set my email server?

Avatar
Discard
Best Answer

Hello willie ho,

If you want to send a static mail, can be directly sent by below steps:

def send_mail(self, cr, uid, context=None):

mail_body="""you can write any html tags and text here"""

mail_vals={

'email_from': email_from,

'email_to':email_to,

'subject': 'Subject',

'body_html': mail_body

}

mail = self.pool.get('mail.mail').create(cr, uid, mail_vals, context=context)

self.pool.get('mail.mail').send(cr, uid, [mail], context=context)

After creating a scheduler method you have to create a scheduler xml record:

<record forcecreate="True" id="ir_cron_scheduler_action" model="ir.cron">

<field name="name">Scheduler</field>

<field eval="True" name="active"/>

<field name="user_id" ref="base.user_root"/>

<field name="interval_number">1</field>

<field name="interval_type">days</field>

<field name="numbercall">-1</field>

<field eval="False" name="doall"/>

<field eval="'model.model'" name="model"/><!--model in which method of scheduler is defined -->

<field eval="'send_mail'" name="function"/>

<field eval="'(True,)'" name="args"/>

</record>

Hope this helps.

Let me know if you want to know solution for sending mail using template!

Thanks and Regards,

Kalpana Hemnani

Avatar
Discard