QQ邮箱SMTP设置
odoo发送邮件配置
以下是发送主体代码
mail_server = self.env['ir.mail_server'].sudo().search([('name', '=', 'System')], limit=1)
if not mail_server:
_logger.info('管理员还未配置名称为System的smtp服务器信息,请联系管理员配置!')
return
if not mail_server.smtp_user or not mail_server.smtp_pass:
_logger.info("邮件发送账号未正确设置,请联系管理员!")
return
mail_values = {
'message_type': 'email', 'subject': '标签冻结',
'mail_server_id': mail_server.id, 'email_from': mail_server.smtp_user,
'email_to': '接收邮箱'
}
temp_mail_html = """
Hi,
<p> 标签冻结通知 </p>
<table border="1" cellspacing="0" cellpadding="0">
<tr style='border:1px solid #000000'>
<td style='padding-right:30px'>标签</td>
<td>产品</td>
<td>批次</td>
<td>数量</td>
<td>生产日期</td>
<td>质保日期</td>
</tr>
"""
for label in label_list:
name, product_code = label.name, label.product_code
product_qty, product_lot = label.product_qty, label.product_lot
warranty_date = ' ' if not label.warranty_date else label.warranty_date
produce_date = ' ' if not label.produce_date else label.produce_date
temp_mail_html += """
<tr><td style='padding-right:30px'>%s</td>
<td style='padding-right:30px'>%s</td>
<td style='padding-right:30px'>%s</td>
<td style='padding-right:30px'>%s</td>
<td style='padding-right:30px'>%s</td>
<td style='padding-right:30px'>%s</td>
</tr> """ % (name, product_code, product_lot, product_qty, produce_date, warranty_date)
temp_mail_html += "" " </table> """
mail_values['body_html'] = temp_mail_html
self.env['mail.mail'].sudo().create(mail_values).send(auto_commit=True)