The Altair Community is migrating to a new platform to provide a better experience for you. In preparation for the migration, the Altair Community is on read-only mode from October 28 - November 6, 2024. Technical support via cases will continue to work as is. For any urgent requests from Students/Faculty members, please submit the form linked here

SendMail Operator with Attachment

JugiJugi RapidMiner Certified Analyst, Member Posts: 12 Contributor II
edited December 2018 in Product Feedback - Resolved

We often start usecases with the first interface to the business user being a mail with results.

This is a really quick way to get results to him without a lot of invest in interface development.

It would be quite handsome to be able to attach one or multiple files to that Mail because it is inconvenient to put data into the body of the mail.

12
12 votes

Fixed and Released · Last Updated

Included in Advanced Reporting extension. IN-2

Comments

  • MarcoBarradasMarcoBarradas Administrator, Employee-RapidMiner, RapidMiner Certified Analyst, Member Posts: 272 Unicorn
    For those who need a solution you can use some Python with to achieve it.
    <?xml version="1.0" encoding="UTF-8"?><process version="8.2.000">
      <context>
        <input/>
        <output/>
        <macros/>
      </context>
      <operator activated="true" class="process" compatibility="8.2.000" expanded="true" name="Process">
        <process expanded="true">
          <operator activated="true" class="generate_data" compatibility="8.2.000" expanded="true" height="68" name="Generate Data" width="90" x="179" y="34"/>
          <operator activated="true" class="python_scripting:execute_python" compatibility="7.4.000" expanded="true" height="82" name="Send_Mail" width="90" x="380" y="34">
            <parameter key="script" value="import datetime&#10;import os&#10;import zipfile&#10;import pandas&#10;import smtplib&#10;from xlsxwriter.utility import xl_rowcol_to_cell&#10;&#10;from email.mime.multipart import MIMEMultipart&#10;from email.mime.text import MIMEText&#10;from email.mime.base import MIMEBase&#10;from email import encoders&#10;writer = pandas.ExcelWriter('file.xlsx', engine='xlsxwriter')&#10;&#10;now = datetime.datetime.now()&#10;&#10;def rm_main(data):&#10;&#9;&#10;&#9;#Passing data to an excel file&#10;&#9;data.to_excel(writer, sheet_name='Name',index=False)&#10;&#9;writer.save()&#10;&#9;path = &quot;file.xlsx&quot;&#10;&#9;&#10;&#10;&#9;&#10;&#9;z = zipfile.ZipFile('zipped_file.zip', 'w')&#10;  &#10;&#9;z.write(path)                   # has to exist&#10;&#9;&#10;&#9;z.close()&#10;&#9;#Define who is going to recieve the file&#10;&#9;fromaddr = &quot;mail@mail.com&quot;&#10;&#9;toaddr = [&quot;customer@mail.com&quot;]&#10; &#10;&#9;msg = MIMEMultipart()&#10; &#10;&#9;msg['From'] = fromaddr&#10;&#9;msg['To'] =  &quot;, &quot;.join(toaddr)&#10;&#9;msg['Subject'] = &quot;Subject&quot;&#10;&#9; &#10;&#9;body = &quot;I'm sending a mail with a ziped file&quot;&#10;&#10;&#9;part = MIMEBase('application', &quot;octet-stream&quot;)&#10;&#9;part.set_payload(open(path2, &quot;rb&quot;).read())&#10;&#9;encoders.encode_base64(part)&#10;&#10;&#9;part.add_header('Content-Disposition', 'attachment; filename=&quot;zipped_file.zip&quot;')&#10;&#10;&#9;msg.attach(part)&#10;&#9;msg.attach(MIMEText(body, 'html'))&#10;&#10;&#9; &#10;&#9;#Configure you SMTP options&#10;&#9;server = smtplib.SMTP('SMTP', 587)&#10;&#9;server.starttls()&#10;&#9;server.login(fromaddr,&quot;YOUR_PASSWORD&quot;)&#10;&#9;#End configuration of email&#10;&#9;text = msg&#10;&#9;&#10;&#9;server.sendmail(fromaddr, toaddr, msg.as_string())&#10;&#9;server.quit()&#10;&#9;return  0"/>
          </operator>
          <connect from_op="Generate Data" from_port="output" to_op="Send_Mail" to_port="input 1"/>
          <connect from_op="Send_Mail" from_port="output 1" to_port="result 1"/>
          <portSpacing port="source_input 1" spacing="0"/>
          <portSpacing port="sink_result 1" spacing="0"/>
          <portSpacing port="sink_result 2" spacing="0"/>
        </process>
      </operator>
    </process>
    

    But I agree it may be great to do it with the Mail operator.

  • sgenzersgenzer Administrator, Moderator, Employee-RapidMiner, RapidMiner Certified Analyst, Community Manager, Member, University Professor, PM Moderator Posts: 2,959 Community Manager
    nice @MarcoBarradas! Can I post this on the community repo? Looks like a cool new "building block" to me. :smile:
Sign In or Register to comment.