# Buggy code
def process(self):
    event = self.receive_message()

    csvfile = io.StringIO()
    writer = csv.DictWriter(
        csvfile,
        fieldnames=self.fieldnames,
        quoting=csv.QUOTE_MINIMAL,
        delimiter=str(";"),
        extrasaction="ignore",
        lineterminator="\n",
    )
    writer.writeheader()
    writer.writerow(event)
    attachment = csvfile.getvalue()

    if self.http_verify_cert and self.smtp_class == smtplib.SMTP_SSL:
        kwargs = {"context": ssl.create_default_context()}
    else:
        kwargs = {}

    with self.smtp_class(
        self.parameters.smtp_host, self.parameters.smtp_port, **kwargs
    ) as smtp:
        if self.starttls:
            if self.parameters.http_verify_cert:
                smtp.starttls(ssl.create_default_context())
            else:
                smtp.starttls()
        if self.username and self.password:
            smtp.auth(smtp.auth_plain, user=self.username, password=self.password)
        msg = MIMEMultipart()
        if self.parameters.text:
            msg.attach(MIMEText(self.parameters.text.format(ev=event)))
        msg.attach(MIMEText(attachment, "csv"))
        msg["Subject"] = self.parameters.subject.format(ev=event)
        msg["From"] = self.parameters.mail_from.format(ev=event)
        msg["To"] = self.parameters.mail_to.format(ev=event)
        print(msg, file=sys.stderr)
        smtp.send_message(
            msg,
            from_addr=self.parameters.mail_from,
            to_addrs=self.parameters.mail_to.format(ev=event),
        )

    self.acknowledge_message()


# Traceback (ValueError)
Traceback (most recent call last):
File "/tmp/intelmq/intelmq/lib/bot.py", line 153, in start
self.process()
File "/tmp/intelmq/intelmq/bots/outputs/smtp/output.py", line 49, in process
smtp.starttls(ssl.create_default_context())
File "/usr/lib/python3.4/smtplib.py", line 686, in starttls
keyfile=keyfile)
File "/usr/lib/python3.4/ssl.py", line 468, in _create_stdlib_context
raise ValueError("certfile must be specified")
ValueError: certfile must be specified

# Fixed code
def process(self):
    event = self.receive_message()

    csvfile = io.StringIO()
    writer = csv.DictWriter(
        csvfile,
        fieldnames=self.fieldnames,
        quoting=csv.QUOTE_MINIMAL,
        delimiter=str(";"),
        extrasaction="ignore",
        lineterminator="\n",
    )
    writer.writeheader()
    writer.writerow(event)
    attachment = csvfile.getvalue()

    if self.http_verify_cert and self.smtp_class == smtplib.SMTP_SSL:
        kwargs = {"context": ssl.create_default_context()}
    else:
        kwargs = {}

    with self.smtp_class(
        self.parameters.smtp_host, self.parameters.smtp_port, **kwargs
    ) as smtp:
        if self.starttls:
            if self.parameters.http_verify_cert:
                smtp.starttls(context=ssl.create_default_context())
            else:
                smtp.starttls()
        if self.username and self.password:
            smtp.auth(smtp.auth_plain, user=self.username, password=self.password)
        msg = MIMEMultipart()
        if self.parameters.text:
            msg.attach(MIMEText(self.parameters.text.format(ev=event)))
        msg.attach(MIMEText(attachment, "csv"))
        msg["Subject"] = self.parameters.subject.format(ev=event)
        msg["From"] = self.parameters.mail_from.format(ev=event)
        msg["To"] = self.parameters.mail_to.format(ev=event)
        print(msg, file=sys.stderr)
        smtp.send_message(
            msg,
            from_addr=self.parameters.mail_from,
            to_addrs=self.parameters.mail_to.format(ev=event),
        )

    self.acknowledge_message()