Reputation: 167
Is there a way to send an email to the person who where assigned a task in a project or to send an email to the project manager when the task is finished ?
I'm working on OpenERP v6.1.
Thanks for the replies
Upvotes: 5
Views: 8191
Reputation: 3743
you can use "email_template" module to send mail. First you need to create a template for that.
If you don't want to create email.template then you can directly use "send mail method" of "mail.message".
def send_email(cr, uid, ids, context=None):
mail_server_obj = self.pool.get('ir.mail_server')
mail_server_ids = mail_server_obj.search(cr, uid, [], context=context)
if mail_server_ids:
mail_message_obj = self.pool.get('mail.message')
email_from = mail_server_obj.browse(cr, uid, mail_server_ids[0], context=context).smtp_user
values = {
'subject': your_subject,
'body_html': your_body_message,
'email_from': email_from,
'email_to': email_to,
'model': model_name,
'res_id': ids[0],
'mail_server_id': mail_server_ids and mail_server_ids[0],
'date': time.strftime('%Y-%m-%d %H:%M:%S'),
'state': 'outgoing',
'subtype': 'html',
}
msg_id = mail_message_obj.create(cr, uid, values, context=context)
if msg_id:
mail_message_obj.send(cr, uid, [msg_id], context=context)
Upvotes: 0
Reputation: 5044
Solution is to use 'email_template' module. install this module and you can find the configuration at Settings > Configuration > Email > Outgoing Mail Servers
. Here you have the setup the outgoing mail server. Then goto Settings > Configuration > Email > Templates
add the email template here for the model you want.
Now inherit your model and in the function (your button object to which change the task state to finish) add search for the corresponding email template and then use the send_mail()
in the email_template module to send the mail.
Upvotes: 3
Reputation: 13342
This can be done in two ways.
Workflows
The "vanilla" way is to use workflows: workflow Activities can trigger a Server Action that sends an e-mail when they are reached. You would need to create a workflow for your object (e.g. project.task
). Remember to modify the view's state buttons from type='object'
to type='workflow'
. You can find an example here.
This can be rather complicated if you're not familiar with module development in OpenERP. And IMHO it's a lot of trouble for such an "obvious" feature.
Automated Actions
That leads us to the second way to do it: using the base_action_rule
module. Unfortunately it turns out that you're rather limited to what you can achieve with the module. So I wrote an extension, base_action_rule_trigger
to simplify the sort of
automation you are trying to achieve.
For example, create a notification when a Project Issue is closed::
changed.get('state') == 'done'
:Other triggers expressions examples:
old.get('user_id') and new.get('user_id') and old.get('user_id') != new.get('user_id')
inserting or changed.get('state') == 'draft' or not new.get('user_id')
Upvotes: 2
Reputation: 16743
You can override button object method,
obj_mail_msg = self.pool.get('mail.message')
obj_mail_server = self.pool.get('ir.mail_server')
mail_server_ids = obj_mail_server.search(cr, uid, [], context=context)
mail_server_record = obj_mail_server.browse(cr, uid, mail_server_ids)[0]
obj_mail_msg.schedule_with_attach(cr, uid,
email_from,
email_to = [list of email],
subject='Notification for Task',
body=tools.ustr(mail_body) or '',
mail_server_id = mail_server_ids[0])
schedule_with_attach will create a massage in (settings > configuration > Email > Massages)
and massage will be send by scheduler.
Hope it will Help.
Upvotes: 3
Reputation: 69
This is what I've used in one of my projects. Perhaps filling in the mail server (smtp) parameters with yours would solve your problem.
import javax.mail.*;
import javax.mail.internet.*;
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host", "smtp.gmail.com");
properties.setProperty("mail.smtp.auth", "true");
properties.put("mail.smtp.starttls.enable", "true");
Session session = Session.getDefaultInstance(properties, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(acc, pass);
}
});
MimeMessage mimeMessage = new MimeMessage(session);
Transport.send(mimeMessage);
Upvotes: -2