1

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

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

用于处理的 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('sateesh.karuturi9@gmail.com', 'password')
    mailserver.sendmail('sateesh.karuturi9@gmail.com',record,msg.as_string())
    output.write(record)
    mailserver.quit()
  except Exception as e:
    error.write(record, str(e))

这是我的错误: 在此处输入图像描述

4

1 回答 1

2

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

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

mailserver.sendmail('sateesh.karuturi9@gmail.com', record.value['text'], msg.as_string())

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

于 2018-09-18T00:45:34.740 回答