<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Splunk Phantom:  How to append each username from LDAP query result into an email body and send? in Splunk SOAR</title>
    <link>https://community.splunk.com/t5/Splunk-SOAR/Splunk-Phantom-How-to-append-each-username-from-LDAP-query/m-p/483361#M275</link>
    <description>&lt;P&gt;Would you be able to post your configuration w/ screenshots or names + params? &lt;/P&gt;</description>
    <pubDate>Mon, 23 Sep 2019 15:46:50 GMT</pubDate>
    <dc:creator>sam_splunk</dc:creator>
    <dc:date>2019-09-23T15:46:50Z</dc:date>
    <item>
      <title>Splunk Phantom:  How to append each username from LDAP query result into an email body and send?</title>
      <link>https://community.splunk.com/t5/Splunk-SOAR/Splunk-Phantom-How-to-append-each-username-from-LDAP-query/m-p/483358#M272</link>
      <description>&lt;P&gt;Results from LDAP query: &lt;BR /&gt;user1&lt;BR /&gt;user2&lt;/P&gt;
&lt;P&gt;I want to send an email for each of this users with the below email body separately:&lt;/P&gt;
&lt;P&gt;Hi user1 (for user 1 email)&lt;/P&gt;
&lt;P&gt;Hi user1 (for user 2 email)&lt;/P&gt;
&lt;P&gt;And then send the email to each of these users.&lt;/P&gt;
&lt;P&gt;====================================================================&lt;/P&gt;
&lt;P&gt;The issue that I am facing is that currently, the email body looks like this:&lt;/P&gt;
&lt;P&gt;Hi user1, user2&lt;/P&gt;
&lt;P&gt;Though the email was successfully to each of these users.&lt;/P&gt;</description>
      <pubDate>Sun, 07 Jun 2020 17:36:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-SOAR/Splunk-Phantom-How-to-append-each-username-from-LDAP-query/m-p/483358#M272</guid>
      <dc:creator>robertbuscato</dc:creator>
      <dc:date>2020-06-07T17:36:16Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Phantom:  How to append each username from LDAP query result into an email body and send?</title>
      <link>https://community.splunk.com/t5/Splunk-SOAR/Splunk-Phantom-How-to-append-each-username-from-LDAP-query/m-p/483359#M273</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;

&lt;P&gt;The easiest way to do this may be a custom code block.&lt;/P&gt;

&lt;P&gt;In my environment, I have an LDAP query from an action block that feeds into a custom function. That function has the inputs:&lt;/P&gt;

&lt;P&gt;get_users_1:action_result.data.&lt;EM&gt;.emails.0&lt;BR /&gt;
get_users_1:action_result.data.&lt;/EM&gt;.displayname&lt;/P&gt;

&lt;P&gt;And the code looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;def custom_function_2(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
    phantom.debug('custom_function_2() called')
    results_data_1 = phantom.collect2(container=container, datapath=['get_users_1:action_result.data.*.emails.0', 'get_users_1:action_result.data.*.displayname'], action_results=results)
    results_item_1_0 = [item[0] for item in results_data_1]
    results_item_1_1 = [item[1] for item in results_data_1]

    ################################################################################
    ## Custom Code Start
    ################################################################################

    for i in range(len(results_item_1_0)):
        parameters = []
        email_body = """
Hello{},

This is a test!
        """
        if results_item_1_0[i] == None:
            continue                    # don't send on empyt emails

        if results_item_1_1[i] == None:
            email_body = email_body.format("")
        else:
            email_body = email_body.format(" " + results_item_1_1[i])

        parameters.append({
            'body': email_body,
            'from': "&amp;lt;REDACTED&amp;gt;@gmail.com",
            'attachments': "",
            'to': results_item_1_0[i],
            'cc': "",
            'bcc': "",
            'headers': "",
            'subject': "Testing"
        })
        phantom.act("send email", parameters=parameters, assets=['gmail'], name="send_email_1")

    ################################################################################
    ## Custom Code End
    ################################################################################
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In this way I am looping through the values and grabbing display name and email and smashing them together to send an email. I do a couple of lightweight error handling too:&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;If the email field is None, we break out of that iteration of the loop to prevent failing to send.&lt;/LI&gt;
&lt;LI&gt;If the Displayname is empty then we just start the email with "Hello," instead of "Hello None,"&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;It would be possible to do this with artifacts and the like, but I think a short code block is more straightforward.  Feel free to reach out to me on the Phantom-Community Slack (sam_phantom) to discuss.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 02:18:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-SOAR/Splunk-Phantom-How-to-append-each-username-from-LDAP-query/m-p/483359#M273</guid>
      <dc:creator>sam_splunk</dc:creator>
      <dc:date>2020-09-30T02:18:58Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Phantom:  How to append each username from LDAP query result into an email body and send?</title>
      <link>https://community.splunk.com/t5/Splunk-SOAR/Splunk-Phantom-How-to-append-each-username-from-LDAP-query/m-p/483360#M274</link>
      <description>&lt;P&gt;Hi Ghays,&lt;/P&gt;

&lt;P&gt;It was able to send email to only one of the emails returned from LDAP (2 users returned which is the expected result).  Also, I noticed that it sends to the second email returned by LDAP.&lt;BR /&gt;
Any update you can recommend? I'm not really good at Python so I'm having a hard time on fixing the issue.&lt;/P&gt;

&lt;P&gt;Thank you.&lt;BR /&gt;
Robert&lt;/P&gt;</description>
      <pubDate>Mon, 23 Sep 2019 06:00:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-SOAR/Splunk-Phantom-How-to-append-each-username-from-LDAP-query/m-p/483360#M274</guid>
      <dc:creator>robertbuscato</dc:creator>
      <dc:date>2019-09-23T06:00:07Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Phantom:  How to append each username from LDAP query result into an email body and send?</title>
      <link>https://community.splunk.com/t5/Splunk-SOAR/Splunk-Phantom-How-to-append-each-username-from-LDAP-query/m-p/483361#M275</link>
      <description>&lt;P&gt;Would you be able to post your configuration w/ screenshots or names + params? &lt;/P&gt;</description>
      <pubDate>Mon, 23 Sep 2019 15:46:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-SOAR/Splunk-Phantom-How-to-append-each-username-from-LDAP-query/m-p/483361#M275</guid>
      <dc:creator>sam_splunk</dc:creator>
      <dc:date>2019-09-23T15:46:50Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Phantom:  How to append each username from LDAP query result into an email body and send?</title>
      <link>https://community.splunk.com/t5/Splunk-SOAR/Splunk-Phantom-How-to-append-each-username-from-LDAP-query/m-p/483362#M276</link>
      <description>&lt;P&gt;Below is the custom code I created. &lt;BR /&gt;
Input Paramaters from LDAP:&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Get_User_Attribute:action_result.data.*.mail&lt;/STRONG&gt;&lt;BR /&gt;
&lt;STRONG&gt;Get_User_Attribute:action_result.data.*.givenname&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;def Format_Email(action=None, success=None, container=None, results=None, handle=None, filtered_artifacts=None, filtered_results=None):
    phantom.debug('Format_Email() called')
    results_data_1 = phantom.collect2(container=container, datapath=['Get_User_Attribute:action_result.data.*.mail', 'Get_User_Attribute:action_result.data.*.givenname'], action_results=results)
    results_item_1_0 = [item[0] for item in results_data_1]
    results_item_1_1 = [item[1] for item in results_data_1]

    ################################################################################
    ## Custom Code Start
    ################################################################################

    # build parameters list for 'Send_Email' call
    for i in range(len(results_item_1_0)):

        parameters = []
        email_body = """
          Hello{},

          This is a test!
            """
        if results_item_1_0[i] == None:
            continue                    # don't send on empyt emails

        if results_item_1_1[i] == None:
            email_body = email_body.format("")
        else:
            email_body = email_body.format(" " + results_item_1_1[i])

            parameters.append({
             'body': email_body,
             'from': "test@mail.com",
             'attachments': "",
             'to': results_item_1_0[i],
             'cc': "",
             'bcc': "",
             'headers': "",
             'subject': "Testing"
      })
    phantom.act("send email", parameters=parameters, assets=['smtp'], name="Send_Email")

    ################################################################################
    ## Custom Code End
    ################################################################################

    return
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Sep 2020 02:15:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-SOAR/Splunk-Phantom-How-to-append-each-username-from-LDAP-query/m-p/483362#M276</guid>
      <dc:creator>robertbuscato</dc:creator>
      <dc:date>2020-09-30T02:15:22Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Phantom:  How to append each username from LDAP query result into an email body and send?</title>
      <link>https://community.splunk.com/t5/Splunk-SOAR/Splunk-Phantom-How-to-append-each-username-from-LDAP-query/m-p/483363#M277</link>
      <description>&lt;P&gt;Confirm the inputs to your custom function are right?&lt;/P&gt;

&lt;P&gt;Should be:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Input 1: Get_User_Attribute:action_result.data.*.emails.0
Input 2: Get_User_Attribute:action_result.data.*.displayname
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Sep 2019 21:28:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-SOAR/Splunk-Phantom-How-to-append-each-username-from-LDAP-query/m-p/483363#M277</guid>
      <dc:creator>sam_splunk</dc:creator>
      <dc:date>2019-09-24T21:28:44Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Phantom:  How to append each username from LDAP query result into an email body and send?</title>
      <link>https://community.splunk.com/t5/Splunk-SOAR/Splunk-Phantom-How-to-append-each-username-from-LDAP-query/m-p/483364#M278</link>
      <description>&lt;P&gt;@ghays_splunk  - It actually works now. I didn't put the proper indention (newbie mistake) in for loop that's why it didn't work before. Thank you so much for helping me.  &lt;/P&gt;</description>
      <pubDate>Wed, 25 Sep 2019 23:20:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-SOAR/Splunk-Phantom-How-to-append-each-username-from-LDAP-query/m-p/483364#M278</guid>
      <dc:creator>robertbuscato</dc:creator>
      <dc:date>2019-09-25T23:20:03Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Phantom:  How to append each username from LDAP query result into an email body and send?</title>
      <link>https://community.splunk.com/t5/Splunk-SOAR/Splunk-Phantom-How-to-append-each-username-from-LDAP-query/m-p/483365#M279</link>
      <description>&lt;P&gt;Awesome! Python is super sensitive to indentation - it's literally a language where the amount of whitespace controls how statements a grouped.. crazy stuff.&lt;/P&gt;

&lt;P&gt;Anywho, glad it working for you!&lt;/P&gt;</description>
      <pubDate>Thu, 26 Sep 2019 14:25:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-SOAR/Splunk-Phantom-How-to-append-each-username-from-LDAP-query/m-p/483365#M279</guid>
      <dc:creator>sam_splunk</dc:creator>
      <dc:date>2019-09-26T14:25:01Z</dc:date>
    </item>
  </channel>
</rss>

