本文整理汇总了Python中tools.email_send函数的典型用法代码示例。如果您正苦于以下问题:Python email_send函数的具体用法?Python email_send怎么用?Python email_send使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了email_send函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _send_reminder
def _send_reminder(self, cr, uid, data, context):
partner = data['form']['partner_id'][0][2]
if partner:
res = pooler.get_pool(cr.dbname).get('ecommerce.partner').browse(cr, uid, partner)
for partner in res:
if partner.address_ids and not partner.address_ids[0].email:
not_sent.append(partner.name)
for adr in partner.address_ids:
if adr.email:
sent_dict[partner.name] = adr.email
name = adr.username or partner.name
to = '%s <%s>' % (name, adr.email)
mail_from = '[email protected]'
attach_ids = pooler.get_pool(cr.dbname).get('ir.attachment').search(cr, uid,
[('res_model', '=', 'ecommerce.shop'),
('res_id', '=', data['ids'][0])])
res_atc = pooler.get_pool(cr.dbname).get('ir.attachment').read(cr, uid,
attach_ids, ['datas_fname', 'datas'])
res_atc = map(lambda x: (x['datas_fname'],
base64.decodestring(x['datas'])), res_atc)
tools.email_send(mail_from, [to], data['form']['subject'], data['form']['message'], attach=res_atc)
return 'finished'
示例2: check_not_sync
def check_not_sync(self, cr, uid, context=None):
entity_obj = self.pool.get('sync.server.entity')
entity_activity_obj = self.pool.get('sync.server.entity.activity')
date_tools = self.pool.get('date.tools')
ids = self.search(cr, uid, [('name', '!=', False)])
if not ids:
return False
template = self.browse(cr, uid, ids[0])
thresold_date = (datetime.now() + timedelta(days=-template.nb_days)).strftime('%Y-%m-%d %H:%M:%S')
entity_to_check_ids = entity_obj.search(cr, uid, [('state', 'in', ['validated', 'updated'])])
if not entity_to_check_ids:
return False
activity_ids = entity_activity_obj.search(cr, uid, [('entity_id', 'in', entity_to_check_ids), ('datetime', '<=', thresold_date)])
if not activity_ids:
return False
warn_ids = []
for act in entity_activity_obj.read(cr, uid, activity_ids, ['entity_id']):
warn_ids.append(act['entity_id'])
emails = template.name.split(',')
subject = _('SYNC_SERVER: instances did not perform any sync')
body = _('''Hello,
The sync server detected that the following instances did not perform any sync since %d days:
''') % template.nb_days
for entity in entity_obj.browse(cr, uid, warn_ids):
body += _(" - %s last sync: %s\n") % (entity.name, entity.last_dateactivity and date_tools.get_date_formatted(cr, uid, 'datetime', entity.last_dateactivity) or _('never'))
body += _("\n\nThis is an automatically generated email, please do not reply.\n")
tools.email_send(False, emails, subject, body)
return True
示例3: request_send
def request_send(self, cr, uid, ids, context={}):
res = super( res_request, self ).request_send( cr, uid, ids, context )
eagle_param = self.__get_eagle_parameters( cr, uid, context=context )
if not eagle_param or not eagle_param.send_mail_with_request:
netsvc.Logger().notifyChannel( 'addons.'+self._name, netsvc.LOG_DEBUG, "The request won't send any email because it's parameterized as is." )
return res
if not tools.config.get('smtp_server'):
netsvc.Logger().notifyChannel( 'addons.'+self._name, netsvc.LOG_DEBUG, "The request can't send any email because there's no stmp server defined..." )
return res
for request in self.browse( cr, uid, ids ):
if not request.send_mail: continue
if not request.act_from.user_email:
netsvc.Logger().notifyChannel( 'addons.'+self._name, netsvc.LOG_DEBUG, "The request '%s' can't send any email because there's no email defined for the sender..." % request.name )
continue
if not request.act_to.user_email:
netsvc.Logger().notifyChannel( 'addons.'+self._name, netsvc.LOG_DEBUG, "The request '%s' can't send any email because there's no email defined for the recipient..." % request.name )
continue
netsvc.Logger().notifyChannel( 'addons.'+self._name, netsvc.LOG_DEBUG, "About to send an email to %s from %s with the following subject: %s" % (request.act_to.user_email,request.act_from.user_email,request.name) )
level = {'0': _('Low'),'1': _('Normal'),'2': _('High')}[request.priority]
tools.email_send(
email_from=request.act_from.user_email,
email_to=[request.act_to.user_email],
subject='['+level+'] '+request.name,
body=request.body
)
return res
示例4: cron_account_analytic_account
def cron_account_analytic_account(self, cr, uid, context=None):
domain = [
('name', 'not ilike', 'maintenance'),
('partner_id', '!=', False),
('user_id', '!=', False),
('user_id.user_email', '!=', False),
('state', 'in', ('draft', 'open')),
'|', ('date', '<', time.strftime('%Y-%m-%d')), ('date', '=', False),
]
account_ids = self.search(cr, uid, domain, context=context, order='name asc')
accounts = self.browse(cr, uid, account_ids, context=context)
users = dict()
for account in accounts:
users.setdefault(account.user_id, dict()).setdefault(account.partner_id, []).append(account)
account.write({'state' : 'pending'}, context=context)
for user, data in users.iteritems():
subject = '[OPENERP] Reporting: Analytic Accounts'
body = Template(MAKO_TEMPLATE).render_unicode(user=user, partners=data)
tools.email_send('[email protected]', [user.user_email, ], subject, body)
return True
示例5: mail_user
def mail_user(self, cr, uid, ids, confirm=False, context=None):
"""
Send email to user
"""
for regestration in self.browse(cr, uid, ids, context=context):
src = regestration.event_id.reply_to or False
email_to = []
email_cc = []
if regestration.email_from:
email_to = regestration.email_from
if regestration.email_cc:
email_cc += [regestration.email_cc]
if not (email_to or email_cc):
continue
subject = ""
body = ""
if confirm:
subject = _('Auto Confirmation: [%s] %s') %(regestration.id, regestration.name)
body = regestration.event_id.mail_confirm
elif regestration.event_id.mail_auto_confirm or regestration.event_id.mail_auto_registr:
if regestration.event_id.state in ['draft', 'fixed', 'open', 'confirm', 'running'] and regestration.event_id.mail_auto_registr:
subject = _('Auto Registration: [%s] %s') %(regestration.id, regestration.name)
body = regestration.event_id.mail_registr
if (regestration.event_id.state in ['confirm', 'running']) and regestration.event_id.mail_auto_confirm:
subject = _('Auto Confirmation: [%s] %s') %(regestration.id, regestration.name)
body = regestration.event_id.mail_confirm
if subject or body:
tools.email_send(src, email_to, subject, body, email_cc=email_cc, openobject_id=regestration.id)
self.history(cr, uid, [regestration], subject, history = True, \
email=email_to, details=body, \
subject=subject, email_from=src, \
email_cc=', '.join(email_cc))
return True
示例6: _mass_mail_send
def _mass_mail_send(self, cr, uid, data, context):
nbr = 0
partners = []
contacts = pooler.get_pool(cr.dbname).get('res.partner.contact').browse(cr, uid, data['ids'], context)
for contact in contacts:
# for adr in partner.address:
if contact.email:
name = contact.name or contact.partner_id.name
to = '%s <%s>' % (name, contact.email)
#TODO: add some tests to check for invalid email addresses
#CHECKME: maybe we should use res.partner/email_send
res = tools.email_send(data['form']['from'], [to], data['form']['subject'], data['form']['text'], subtype='html')
nbr += 1
else:
for adr in contact.partner_id.address:
if adr.email:
name = adr.name or partner.name
to = '%s <%s>' % (name, adr.email)
#TODO: add some tests to check for invalid email addresses
#CHECKME: maybe we should use res.partner/email_send
res = tools.email_send(data['form']['from'], [to], data['form']['subject'], data['form']['text'], subtype='html')
nbr += 1
pooler.get_pool(cr.dbname).get('res.partner.event').create(cr, uid,
{'name': 'Email sent through mass mailing From Contact',
'partner_id': contact.partner_id.id,
'description': data['form']['text'], })
partners.append(contact.partner_id.id)
data['form']['partners'] = partners
data['form']['nbr'] = nbr
if data['form']['event']:
return 'open'
return 'ok'
示例7: _mass_mail_send
def _mass_mail_send(self, cr, uid, data, context):
nbr = 0
partners = []
jobs = pooler.get_pool(cr.dbname).get('res.partner.job').browse(cr, uid, data['ids'], context)
for job in jobs:
if job.email:
name = job.address_id.name or job.name.name
to = '%s <%s>' % (name, job.email)
#TODO: add some tests to check for invalid email addresses
#CHECKME: maybe we should use res.partner/email_send
res = tools.email_send(data['form']['from'], [to], data['form']['subject'], data['form']['text'], subtype='html')
nbr += 1
elif job.address_id.email:
name = job.address_id.name or job.name.name
to = '%s <%s>' % (name, job.address_id.email)
res = tools.email_send(data['form']['from'], [to], data['form']['subject'], data['form']['text'], subtype='html')
nbr += 1
pooler.get_pool(cr.dbname).get('res.partner.event').create(cr, uid,
{'name': 'Email sent through mass mailing from Job',
'partner_id': job.name and job.name.id or job.address_id.partner_id.id,
'description': data['form']['text'], })
partners.append(job.name and job.name.id or job.address_id.partner_id.id)
data['form']['nbr'] = nbr
data['form']['partners'] = partners
if data['form']['event']:
return 'open'
return 'ok'
示例8: _send_email
def _send_email(self, cr, uid, sender, recipient, subject, body):
self._log('Tentative d\'envoi du mail')
self._log('Envoi d\'un e-mail a ' + recipient + '. Sujet: ' + subject)
tools.email_send(email_from=sender, email_to=[recipient] , \
subject=subject, body=body, cr=cr)
self._debug("Sending email to " + recipient + ". " + \
"Subject: \"" + subject + "\"")
开发者ID:Prisme-Solutions-Informatique-SA,项目名称:PRISME-ODOO,代码行数:7,代码来源:data_prisme_warranty_warranty.py
示例9: run_auto_import
def run_auto_import(self, cr, uid, automatic=False, use_new_cursor=False, context=None):
pool = pooler.get_pool(cr.dbname)
#import pdb;pdb.set_trace()
testo_log = """Inizio procedura di aggiornamento/inserimento articoli """+time.ctime()+'\n'
percorso='/home/openerp/filecsv'
partner_obj = pool.get('res.partner')
if use_new_cursor:
cr = pooler.get_db(use_new_cursor).cursor()
elenco_csv = os.listdir(percorso)
for filecsv in elenco_csv:
codfor=filecsv.split(".")
testo_log = testo_log + " analizzo file "+codfor[0]+".csv \n"
fornitore_ids = partner_obj.search(cr,uid,[('ref', '=',codfor[0])])
if fornitore_ids:
fornitore_id = fornitore_ids[0]
lines = csv.reader(open(percorso+'/'+filecsv,'rb'),delimiter=";")
#import pdb;pdb.set_trace()
res = self._import_product_func(cr, uid, lines, fornitore_id, context)
testo_log = testo_log + " Inseriti "+str(res[0])+" Aggiornati "+str(res[1]) +" Articoli \n"
else:
testo_log = testo_log + " fornitore "+codfor[0]+" non trovato \n"
os.remove(percorso+'/'+filecsv)
testo_log = testo_log + " Operazione Teminata alle "+time.ctime()+"\n"
#invia e-mail
type_ = 'plain'
tools.email_send('[email protected]',
['[email protected]'],
'Import Automatico Articoli',
testo_log,
subtype=type_,
)
return
示例10: _check
def _check(self, cr, uid, context={}):
req = cr.execute("SELECT DISTINCT email_alert FROM hr_employee WHERE email_alert is not null")
mails = cr.dictfetchall(req)
emails=[]
for mail in mails:
req = cr.execute("SELECT name, medic_exam, last_medic_exam, medic_exam_alert FROM hr_employee WHERE medic_exam_alert < NOW() and email_alert=%s",(mail['email_alert'],))
res = cr.dictfetchall(req)
email=[]
if res :
email.append(mail['email_alert'])
body="liste des visites médicales à passer\n"
body+="-----------------------------------------------------------\n"
body+="| date alerte | date visite | Nom\n"
for line in res:
body+="| "+line['medic_exam_alert']+" | "+line['medic_exam']+" | "+line['name']+"\n"
body+="-----------------------------------------------------------\n"
body+="Cette email a été envoyé par tinyerp sur :"+mail['email_alert']+"\n"
email_from = "[email protected]"
subject = "Alerte Visite Médicale"
#print body
email_cc= False
email_bcc=False
on_error=False
reply_to=False
attach=None
tinycrm=False
"""Send an email."""
#print "Run medical exam Cron"
tools.email_send(email_from, email, subject, body, email_cc=None, email_bcc=None, on_error=False, reply_to=False, tinycrm=False)
return True
示例11: remind_user
def remind_user(self, cr, uid, ids, context=None, attach=False, destination=True):
"""
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current user’s ID for security checks,
@param ids: List of case's IDs to remind
@param context: A standard dictionary for contextual values
"""
for case in self.browse(cr, uid, ids, context=context):
if not destination and not case.email_from:
return False
if not case.user_id.user_email:
return False
if destination and case.section_id.user_id:
case_email = case.section_id.user_id.user_email
else:
case_email = case.user_id.user_email
src = case_email
dest = case.user_id
body = case.description or ""
if case.message_ids:
body = case.message_ids[0].description or ""
if not destination:
src, dest = dest, case.email_from
if body and case.user_id.signature:
if body:
body += "\n\n%s" % (case.user_id.signature)
else:
body = "\n\n%s" % (case.user_id.signature)
body = self.format_body(body)
attach_to_send = None
if attach:
attach_ids = self.pool.get("ir.attachment").search(
cr, uid, [("res_model", "=", self._name), ("res_id", "=", case.id)]
)
attach_to_send = self.pool.get("ir.attachment").read(cr, uid, attach_ids, ["datas_fname", "datas"])
attach_to_send = map(lambda x: (x["datas_fname"], base64.decodestring(x["datas"])), attach_to_send)
# Send an email
subject = "Reminder: [%s] %s" % (str(case.id), case.name)
tools.email_send(
src,
[dest],
subject,
body,
reply_to=case.section_id.reply_to or "",
openobject_id=str(case.id),
attach=attach_to_send,
)
self._history(
cr, uid, [case], _("Send"), history=True, subject=subject, email=dest, details=body, email_from=src
)
return True
示例12: _action
def _action(self, cr, uid, cases, state_to, scrit=None, context={}):
super(crm_case, self)._action(cr, uid, cases, state_to, scrit=None, context={})
if not scrit:
scrit = []
action_obj = self.pool.get('crm.case.rule')
action_ids= action_obj.search(cr, uid, scrit)
actions = self.pool.get('crm.case.rule').browse(cr, uid, action_ids, context)
category={}
cat_obj = self.pool.get('crm.bayes.categories')
cat_rec = cat_obj.read(cr, uid, cat_obj.search(cr, uid, []),['name'])
for cat in cat_rec:
category[cat['name']] = cat['id']
for case in cases:
for action in actions:
if action.category_id == case.category_id:
if action.action == "don't perform statistic test":
break
result_perform = self.guess_message(cr, uid, case.id, context)
if action.action == "perform action only":
if result_perform:
res = max(result_perform, key=lambda k: k[1])
if res[1] >= action.main_category_rate:
self.write(cr, uid, case.id, {'category_id':category[res[0]]})
elif action.sec_category_rate :
sec_result = copy.deepcopy(result_perform)
sec_result.pop(sec_result.index (max (result_perform, key=lambda k: k[1])))
if sec_result:
re = max(sec_result, key=lambda k: k[1])
if re[1] <= action.main_category_rate and re[1] >= action.sec_category_rate:
self.write(cr, uid, case.id, {'category_id':category[re[0]]})
elif action.action == "perform action and assign category" :
if result_perform :
max_list = max(result_perform, key=lambda k: k[1])
self.write(cr, uid, case.id, {'category_id':category[max_list[0]]})
cate = self.read(cr, uid, case.id, ['category_id'])
if cate['category_id'] :
a_ids = action_obj.search(cr, uid,[('category_id','=',cate['category_id'][0])])
action_rec = action_obj.browse(cr,uid,a_ids[0])
if action_rec:
if action_rec.category_id.name == cate['category_id'][1] and case.email_from :
emails = []
emails.append(case.email_from)
if len(emails) and action_rec.act_mail_body:
body = action_rec.act_mail_body
if case.user_id and case.user_id.address_id and case.user_id.address_id.email:
emailfrom = case.user_id.address_id.email
else:
emailfrom = case.section_id.reply_to
name = '[%d] %s' % (case.id, case.name.encode('utf8'))
reply_to = case.section_id.reply_to or False
if reply_to: reply_to = reply_to.encode('utf8')
if emailfrom:
tools.email_send(emailfrom, emails, name, body, reply_to=reply_to, tinycrm=str(case.id))
break
return True
示例13: _create_user
def _create_user(self, cr, uid, data, context):
pool = pooler.get_pool(cr.dbname)
portal = pool.get("portal.portal").browse(cr, uid, data["form"]["portal_id"])
user_ref = pool.get("res.users")
out = "login,password\n"
skipped = 0
existing = ""
created = ""
for partner in pool.get("res.partner").browse(cr, uid, data["ids"]):
for addr in partner.address:
if not addr.email:
skipped += 1
continue
user = user_ref.search(cr, uid, [("login", "=", addr.email)])
if user:
user = user_ref.browse(cr, uid, user[0])
existing += "- %s (Login: %s, Password: %s)\n" % (user.name, addr.email, user.password)
mail = data["form"]["mail"] % {"login": addr.email, "passwd": user.password}
if data["form"]["send_mail_existing"]:
if not data["form"]["mail_from"]:
raise wizard.except_wizard("Error !", 'Please provide a "from" email address.')
tools.email_send(
data["form"]["mail_from"], [addr.email], data["form"]["mail_subject_existing"], mail
)
continue
passwd = genpasswd()
out += addr.email + "," + passwd + "\n"
user_ref.create(
cr,
uid,
{
"name": addr.name or "Unknown",
"login": addr.email,
"password": passwd,
"address_id": addr.id,
"action_id": portal.home_action_id and portal.home_action_id.id or portal.menu_action_id.id,
"menu_id": portal.menu_action_id.id,
"groups_id": [(4, portal.group_id.id)],
"company_id": portal.company_id.id,
},
)
mail = data["form"]["mail"] % {"login": addr.email, "passwd": passwd}
if data["form"]["send_mail"]:
if not data["form"]["mail_from"]:
raise wizard.except_wizard("Error !", 'Please provide a "from" email address.')
tools.email_send(data["form"]["mail_from"], [addr.email], data["form"]["mail_subject"], mail)
created += "- %s (Login: %s, Password: %s)\n" % (addr.name or "Unknown", addr.email, passwd)
note = ""
if created:
note += "Created users:\n%s\n" % (created)
if existing:
note += "Already existing users:\n%s\n" % (existing)
if skipped:
note += "%d contacts where ignored (an email address is missing).\n" % (skipped)
return {"note": note}
示例14: button_done
def button_done(self, cr, uid, ids, context):
evaluation_obj = self.pool.get('hr.evaluation')
setting_obj = self.pool.get('hr.evaluation.setting')
answ_obj = pooler.get_pool(cr.dbname).get('hr.evaluation.values')
eval_form_obj = self.pool.get('hr.evaluation.form')
users_obj = self.pool.get('res.users')
criteria_obj = self.pool.get('hr.evaluation.criteria')
curr_employee = evaluation_obj.browse(cr, uid, ids)[0].employee_id
setting_id = []
employee_obj = self.pool.get('hr.employee')
employee_ids = employee_obj.search(cr, uid, [('parent_id', '=', curr_employee.id)])
mail_send = users_obj.browse(cr, uid, uid).address_id
email_from = mail_send and mail_send.email or None
subject = 'Notification for Evaluation'
body = 'Please fill forms of evaluation!'
employee_ids.append(curr_employee.id)
if curr_employee.parent_id:
employee_ids.append(curr_employee.parent_id.id)
for evaluation in evaluation_obj.browse(cr, uid, ids):
for employee in employee_obj.browse(cr, uid, employee_ids):
## ADdd criteria basing on products
new_criteria_ids = []
prdct_id = employee.product_id.id
if prdct_id:
setting_id = setting_obj.search(cr, uid, [('product_id', '=', prdct_id)])
if setting_id:
setting_ids = setting_obj.browse(cr, uid, setting_id)
for set_id in setting_ids:
for crit in set_id.criteria_ids:
# new_criteria_ids.append(criteria_obj.copy(cr, uid, crit.id,{}))
new_criteria_ids.append(crit.id)
# for crit in curr_employee.grid_id.criteria_ids:
# new_criteria_ids.append(criteria_obj.copy(cr, uid, crit.id,{'grid_id':False}))
if not setting_id:
raise osv.except_osv(_('Error'), _('Please set a job that defines setting to your employee "%s"!') % (employee.name or ''))
mail_emp = self.browse(cr, uid, employee).user_id
email_to = mail_emp and mail_emp.address_id and mail_emp.address_id.email or None
if email_to:
tools.email_send(email_from, email_to, subject, body, None)
eval_id = eval_form_obj.create(cr, uid, {
'name': evaluation.name + ((evaluation.next_eval and'/' + evaluation.next_eval) or ''),
'employee_id': evaluation.employee_id.id,
'employee_id2': employee.id,
'eval_id': evaluation.id,
'state': 'draft',
'setting_id': setting_id and setting_id[0] or None,
# 'criteria_ids':[(6,0, new_criteria_ids)]
}, context)
item = eval_form_obj.browse(cr, uid, eval_id)
for crit in new_criteria_ids:
answ_obj.create(cr, uid, {'employee_id': item.employee_id.id,
'criteria_id': crit,
'form_id': eval_id,
})
self.write(cr, uid, ids, {'state': 'pending'})
return True
示例15: send_mail
def send_mail(self, cr, uid, ids, context=None):
hr_evaluation_interview_obj = self.pool.get('hr.evaluation.interview')
evaluation_data = self.read(cr, uid, ids, context=context)[0]
current_interview = hr_evaluation_interview_obj.browse(cr, uid, evaluation_data.get('evaluation_id'))
if current_interview.state == "waiting_answer" and current_interview.user_to_review_id.work_email :
msg = " Hello %s, \n\n Kindly post your response for '%s' survey interview. \n\n Thanks," %(current_interview.user_to_review_id.name, current_interview.survey_id.title)
tools.email_send(tools.config['email_from'], [current_interview.user_to_review_id.work_email],\
'Reminder to fill up Survey', msg)
return {'type': 'ir.actions.act_window_close'}