使用Streamset发送电子邮件时出错

问题描述 投票:1回答:1

我正在尝试使用StreamSet发送电子邮件。

为此,我使用Directory作为源(文本文件中的收据列表)和

用于处理的Jython评估器和用于目标的垃圾(仅用于测试)。

当我运行管道,运行没有任何错误。但收到错误邮件到我的sender_email像这样:

Your message wasn't delivered to com.streamsets.pipeline.stage.processor.scripting.ScriptRecord@3ea57368 because the domain 3ea57368 couldn't be found. Check for typos or unnecessary spaces and try again.

这是我的示例代码:

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import logging
for record in records:
  try:
    msg = MIMEMultipart()
    msg['Subject'] = 'simple email in python'
    message = 'here is the email'
    msg.attach(MIMEText(message))
    mailserver = smtplib.SMTP('smtp.gmail.com',587)
    mailserver.ehlo()
    mailserver.starttls()
    mailserver.ehlo()
    mailserver.login('[email protected]', 'password')
    mailserver.sendmail('[email protected]',record,msg.as_string())
    output.write(record)
    mailserver.quit()
  except Exception as e:
    error.write(record, str(e))

这是我的错误:enter image description here

email jython streamsets
1个回答
2
投票

你看到这个是因为你使用记录对象作为电子邮件地址 - com.streamsets.pipeline.stage.processor.scripting.ScriptRecord@3ea57368是记录实例的字符串值。

如果您在目录原点中使用文本数据格式,则可以使用record.value['text']而不是record

mailserver.sendmail('[email protected]', record.value['text'], msg.as_string())

如果您使用的是其他数据格式(分隔符,JSON等),请使用预览来确定电子邮件地址所在的字段,并以相同的方式引用它。

© www.soinside.com 2019 - 2024. All rights reserved.