Error sending email , expected MIME Type, got Null?

Using 7.9.23. Trying to send a report with the following script -

def sendReport(endDateDT=None):
    """
    How will we determine what counts as marked?  should marked really be a datetime?  Perhaps.  Or based on when the entry was entered?
    An old entry from months ago that gets marked this week - should that be sent for instance.
    """
    LOGGER.info("Trying to send report")
    if endDateDT is None:
        endDateDT = system.date.now()
    LOGGER.info("Using date %s"%(str(endDateDT)))
    reportName = 'DPD Weeklies Projects Updates'
    action = 'email'
    reportParameters = {'endDate':endDateDT}
    endDate = system.date.format(endDateDT, 'yyyy-MM-dd')
    project = 'DPDWeeklies'
    body = "Cooleagues,\n\nBelow are the project updates for the week.\n\nPlease feel free to reach out if you have any questions regarding the updates.\n\nThanks"
    actionSettings = {'to':['keyur.parikh@bms.com'], 'smtpServerName':'Weekly Hot Topics Mailer', 'from':'DPDWeeklies@bms.com', 'subject':'DPD Weeklies w/e %s'%(endDate),"body":body}
    reportData = system.report.executeReport(path=reportName, project=project, parameters=reportParameters, fileType='pdf')
    fileName = 'DPD Weeklies Updates %s'%(str(endDate))
    print fileName
    print type(reportData)
    system.net.sendEmail(smtpProfile='Weekly Hot Topics Mailer', fromAddr='testEmail@test.com', subject='DPD Weeklies w/e %s'%(endDate), body=body, to=['testEmail@test.com'], attachmentNames=[fileName], attachmentData=[reportData])
#    system.report.executeAndDistribute(path=reportName, project=project, parameters=reportParameters, action=action, actionSettings=actionSettings)
    LOGGER.info("Finished trying to send report")

I am getting an error on the system.net.sendEmail part the error and not sure why. Apologies for screen shot, operator is remoted in a few layers deep and cannot copy paste for some reason -

My sendEmail line does work if I leave off the attachmentNames and attachmentData kwargs, so I hting that is the issue but I don't know why. My print statements shows the filename to be DPD Weeklies Updates 2023-08-18 and the type of reportData as <type 'array.array'>. Any ideas what is going on?

Good news; we already fixed the underlying limitation here and made it more flexible.
Bad news: it's fixed in 8.1.22 and up.

See this thread for more context:

And more details on how it works are in system.net.sendEmail:
https://docs.inductiveautomation.com/display/DOC81/system.net.sendEmail

1 Like

Ah. Ok. Unfortunately this customer has no impending plans to upgrade to 8.1.xx or pay for the 8 license in the forseeable future but luckily Phil linked https://javaee.github.io/javamail/docs/api/ so I will have to give it the old college try myself.

I got this working without any using java libraries or upgrading.

Changing this -
fileName = 'DPD Weeklies Updates %s'%(str(endDate))
to
fileName = 'DPD Weeklies Updates %s.pdf'%(str(endDate))
made everything work correctly.

2 Likes