0

I am trying to create Jira tickets with python. The Problem is in order to create the ticket in Jira I need the "To" option, to assign it the "CC" option is needed as a dedicated field. In bash I used to do as follows and ticket was correctly created and assigned:

/usr/bin/mail -s "$SUBJECT" -c "$CC" -b "$BCC" "$TO" <<EOF
$Text
EOF

Is there a similar way to do so in Python? I tried with smtplib without success.

Thanks

Max
  • 543
  • 6
  • 17

1 Answers1

0

I found the solution with subprocess. It might not be the most elegant way, but it does the job. Here is my code:

import os
from subprocess import Popen, PIPE


def sendMail(text):
    sendmail_path = "/usr/sbin/sendmail"
    p = os.popen("%s -t" % sendmail_path, "w")
    p.write("To: %s\n" % "jira@company.com")
    p.write("CC: %s\n" % "assignee@company.com")
    p.write("Subject: Hello Python!\n")
    p.write("\n")
    p.write(text)
    stat = p.close()
    if stat != 0:
        print "Error status", stat

sendMail("This E-Mail is sent with Python :)")

I'll improve it by catching some exceptions.

Thanks

Max
  • 543
  • 6
  • 17