可以参考 n8n 流程系统里面的 SMTP 邮件发送的实现方式,我认为是很适合明道云的流程系统的
请
登录后发表观点
你瞅啥? 2023-03-24 08:45:50就是在 SaaS 环境的工作流中使用的
发送附件的,复制代码发给 chatgpt,让他修改成可以发送附件的就好了import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from email.mime.application import MIMEApplication from email.header import Header # 各参数 # 收件人列表 receivers_list = input["receivers_list_in"] # receivers_list = ','.join(receivers_list_in) # 抄送人-CEO邮箱列表 cc_ceo_list = input["cc_ceo_list_in"] # cc_ceo_list = ','.join(cc_ceo_list_in) # 抄送人-财务邮箱列表 cc_finance_list = input["cc_finance_list_in"] # cc_finance_list = ','.join(cc_finance_list_in) # 抄送人-总部邮箱列表 cc_headquarters_list = input["cc_headquarters_list_in"] # cc_headquarters_list = ','.join(cc_headquarters_list_in) # 邮件配置 smtp_server = 'smtp.qiye.163.com' smtp_port = 25 smtp_user = '***' smtp_password = '***' # 发件人 sender = '***' # 收件人 receivers = [receivers_list] # 抄送人 cc = [cc_ceo_list,cc_finance_list,cc_headquarters_list] # 创建邮件对象 message = MIMEMultipart() message['From'] = Header('***', 'utf-8') message['To'] = ','.join(receivers) message['Cc'] = ','.join(cc) message['Subject'] = Header('邮件标题', 'utf-8') # 邮件正文 html = """ <html> <body> <p>邮件正文</p> </body> </html> """ # 添加附件 file_path = "附件路径" with open(file_path, 'rb') as f: attachment = MIMEApplication(f.read()) attachment.add_header('Content-Disposition', 'attachment', filename="附件名称") message.attach(attachment) # 发送邮件 try: smtpObj = smtplib.SMTP(smtp_server, smtp_port) smtpObj.login(smtp_user, smtp_password) smtpObj.sendmail(sender, receivers + cc, message.as_string()) print('邮件发送成功!') except smtplib.SMTPException as e: print('邮件发送失败:', e) output = {'hello': receivers_list}
DEADLINE_EXCEEDED: ClientCall was cancelled at or after deadline.saas 直接超时了。。,私有部署就提示前面的,好尴尬
如果接收邮件呢?
你瞅啥? 2023-03-24 08:29:05可以用 python 代码块实现:
import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from email.header import Header # 各参数 # 收件人列表 receivers_list = input["receivers_list_in"] # receivers_list = ','.join(receivers_list_in) # 抄送人-CEO邮箱列表 cc_ceo_list = input["cc_ceo_list_in"] # cc_ceo_list = ','.join(cc_ceo_list_in) # 抄送人-财务邮箱列表 cc_finance_list = input["cc_finance_list_in"] # cc_finance_list = ','.join(cc_finance_list_in) # 抄送人-总部邮箱列表 cc_headquarters_list = input["cc_headquarters_list_in"] # cc_headquarters_list = ','.join(cc_headquarters_list_in) # 邮件配置 smtp_server = 'smtp.qiye.163.com' smtp_port = 25 smtp_user = '***' smtp_password = '***' # 发件人 sender = '***' # 收件人 receivers = [receivers_list] # 抄送人 cc = [cc_ceo_list,cc_finance_list,cc_headquarters_list] # 创建邮件对象 message = MIMEMultipart() message['From'] = Header('***', 'utf-8') message['To'] = ','.join(receivers) message['Cc'] = ','.join(cc) message['Subject'] = Header('邮件标题', 'utf-8') # 邮件正文 html = """ <html> <body> <p>邮件正文</p> </body> </html> """ # 发送邮件 try: smtpObj = smtplib.SMTP(smtp_server, smtp_port) smtpObj.login(smtp_user, smtp_password) smtpObj.sendmail(sender, receivers + cc, message.as_string()) print('邮件发送成功!') except smtplib.SMTPException as e: print('邮件发送失败:', e) output = {'hello': receivers_list}
👍
腾讯系的坑
企微的邮箱发不出
frank.lin 2023-03-24 08:47:56学到了
谢谢支持,很有帮助,可以利用代码块封装业务流程了
你瞅啥? 2023-03-24 08:45:50就是在 SaaS 环境的工作流中使用的
发送附件的,复制代码发给 chatgpt,让他修改成可以发送附件的就好了import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from email.mime.application import MIMEApplication from email.header import Header # 各参数 # 收件人列表 receivers_list = input["receivers_list_in"] # receivers_list = ','.join(receivers_list_in) # 抄送人-CEO邮箱列表 cc_ceo_list = input["cc_ceo_list_in"] # cc_ceo_list = ','.join(cc_ceo_list_in) # 抄送人-财务邮箱列表 cc_finance_list = input["cc_finance_list_in"] # cc_finance_list = ','.join(cc_finance_list_in) # 抄送人-总部邮箱列表 cc_headquarters_list = input["cc_headquarters_list_in"] # cc_headquarters_list = ','.join(cc_headquarters_list_in) # 邮件配置 smtp_server = 'smtp.qiye.163.com' smtp_port = 25 smtp_user = '***' smtp_password = '***' # 发件人 sender = '***' # 收件人 receivers = [receivers_list] # 抄送人 cc = [cc_ceo_list,cc_finance_list,cc_headquarters_list] # 创建邮件对象 message = MIMEMultipart() message['From'] = Header('***', 'utf-8') message['To'] = ','.join(receivers) message['Cc'] = ','.join(cc) message['Subject'] = Header('邮件标题', 'utf-8') # 邮件正文 html = """ <html> <body> <p>邮件正文</p> </body> </html> """ # 添加附件 file_path = "附件路径" with open(file_path, 'rb') as f: attachment = MIMEApplication(f.read()) attachment.add_header('Content-Disposition', 'attachment', filename="附件名称") message.attach(attachment) # 发送邮件 try: smtpObj = smtplib.SMTP(smtp_server, smtp_port) smtpObj.login(smtp_user, smtp_password) smtpObj.sendmail(sender, receivers + cc, message.as_string()) print('邮件发送成功!') except smtplib.SMTPException as e: print('邮件发送失败:', e) output = {'hello': receivers_list}
学到了
frank.lin 2023-03-24 08:41:19这个 SaaS 版可用吗?能再来个发附件的案例吗
就是在 SaaS 环境的工作流中使用的
发送附件的,复制代码发给 chatgpt,让他修改成可以发送附件的就好了
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication
from email.header import Header
# 各参数
# 收件人列表
receivers_list = input["receivers_list_in"]
# receivers_list = ','.join(receivers_list_in)
# 抄送人-CEO邮箱列表
cc_ceo_list = input["cc_ceo_list_in"]
# cc_ceo_list = ','.join(cc_ceo_list_in)
# 抄送人-财务邮箱列表
cc_finance_list = input["cc_finance_list_in"]
# cc_finance_list = ','.join(cc_finance_list_in)
# 抄送人-总部邮箱列表
cc_headquarters_list = input["cc_headquarters_list_in"]
# cc_headquarters_list = ','.join(cc_headquarters_list_in)
# 邮件配置
smtp_server = 'smtp.qiye.163.com'
smtp_port = 25
smtp_user = '***'
smtp_password = '***'
# 发件人
sender = '***'
# 收件人
receivers = [receivers_list]
# 抄送人
cc = [cc_ceo_list,cc_finance_list,cc_headquarters_list]
# 创建邮件对象
message = MIMEMultipart()
message['From'] = Header('***', 'utf-8')
message['To'] = ','.join(receivers)
message['Cc'] = ','.join(cc)
message['Subject'] = Header('邮件标题', 'utf-8')
# 邮件正文
html = """
<html>
<body>
<p>邮件正文</p>
</body>
</html>
"""
# 添加附件
file_path = "附件路径"
with open(file_path, 'rb') as f:
attachment = MIMEApplication(f.read())
attachment.add_header('Content-Disposition', 'attachment', filename="附件名称")
message.attach(attachment)
# 发送邮件
try:
smtpObj = smtplib.SMTP(smtp_server, smtp_port)
smtpObj.login(smtp_user, smtp_password)
smtpObj.sendmail(sender, receivers + cc, message.as_string())
print('邮件发送成功!')
except smtplib.SMTPException as e:
print('邮件发送失败:', e)
output = {'hello': receivers_list}
你瞅啥? 2023-03-24 08:29:05可以用 python 代码块实现:
import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from email.header import Header # 各参数 # 收件人列表 receivers_list = input["receivers_list_in"] # receivers_list = ','.join(receivers_list_in) # 抄送人-CEO邮箱列表 cc_ceo_list = input["cc_ceo_list_in"] # cc_ceo_list = ','.join(cc_ceo_list_in) # 抄送人-财务邮箱列表 cc_finance_list = input["cc_finance_list_in"] # cc_finance_list = ','.join(cc_finance_list_in) # 抄送人-总部邮箱列表 cc_headquarters_list = input["cc_headquarters_list_in"] # cc_headquarters_list = ','.join(cc_headquarters_list_in) # 邮件配置 smtp_server = 'smtp.qiye.163.com' smtp_port = 25 smtp_user = '***' smtp_password = '***' # 发件人 sender = '***' # 收件人 receivers = [receivers_list] # 抄送人 cc = [cc_ceo_list,cc_finance_list,cc_headquarters_list] # 创建邮件对象 message = MIMEMultipart() message['From'] = Header('***', 'utf-8') message['To'] = ','.join(receivers) message['Cc'] = ','.join(cc) message['Subject'] = Header('邮件标题', 'utf-8') # 邮件正文 html = """ <html> <body> <p>邮件正文</p> </body> </html> """ # 发送邮件 try: smtpObj = smtplib.SMTP(smtp_server, smtp_port) smtpObj.login(smtp_user, smtp_password) smtpObj.sendmail(sender, receivers + cc, message.as_string()) print('邮件发送成功!') except smtplib.SMTPException as e: print('邮件发送失败:', e) output = {'hello': receivers_list}
这个 SaaS 版可用吗?能再来个发附件的案例吗
可以用 python 代码块实现:
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.header import Header
# 各参数
# 收件人列表
receivers_list = input["receivers_list_in"]
# receivers_list = ','.join(receivers_list_in)
# 抄送人-CEO邮箱列表
cc_ceo_list = input["cc_ceo_list_in"]
# cc_ceo_list = ','.join(cc_ceo_list_in)
# 抄送人-财务邮箱列表
cc_finance_list = input["cc_finance_list_in"]
# cc_finance_list = ','.join(cc_finance_list_in)
# 抄送人-总部邮箱列表
cc_headquarters_list = input["cc_headquarters_list_in"]
# cc_headquarters_list = ','.join(cc_headquarters_list_in)
# 邮件配置
smtp_server = 'smtp.qiye.163.com'
smtp_port = 25
smtp_user = '***'
smtp_password = '***'
# 发件人
sender = '***'
# 收件人
receivers = [receivers_list]
# 抄送人
cc = [cc_ceo_list,cc_finance_list,cc_headquarters_list]
# 创建邮件对象
message = MIMEMultipart()
message['From'] = Header('***', 'utf-8')
message['To'] = ','.join(receivers)
message['Cc'] = ','.join(cc)
message['Subject'] = Header('邮件标题', 'utf-8')
# 邮件正文
html = """
<html>
<body>
<p>邮件正文</p>
</body>
</html>
"""
# 发送邮件
try:
smtpObj = smtplib.SMTP(smtp_server, smtp_port)
smtpObj.login(smtp_user, smtp_password)
smtpObj.sendmail(sender, receivers + cc, message.as_string())
print('邮件发送成功!')
except smtplib.SMTPException as e:
print('邮件发送失败:', e)
output = {'hello': receivers_list}