<p>As long as you have control of the CSV on upload, you could change its name to <code>filename_test@test.test.csv</code> (or some other properly escaped filename with the current user's email address in it). Then get the filename from the feed (must be in there somewhere) and extract the email address.</p>

<p>Bit of a workaround, but if it works, it works.</p>

CC BY-SA 4.0
2020-02-20T10:26:15.907Z
This is very creative I like it! However there may be times that another user selects a pre-uploaded CSV from another user so I'm not sure this will work for me. I will sit on it a little bit, but if it turns out this is the only way (which it seems it may be) I will give you that green tick!
dmatthams
CC BY-SA 4.0
2020-02-19T20:36:10.067Z
2020-02-19T20:36:10.067Z
Paul
<p>I have made a custom module that allows a user to upload a CSV and import it using a FeedMe feed. This all works fine, however I want to send an e-mail to the user when the import has completed.</p>

<p>I have this so far, but realised it doesn't work because the event doesn't have access to the user session:</p>

<pre><code>Event::on(Process::class, Process::EVENT_AFTER_PROCESS_FEED, function(FeedProcessEvent $event) {                
    $email = Craft::$app-&gt;getUser()-&gt;getIdentity()-&gt;email;
    if ($event-&gt;feed-&gt;id === getenv('USER_FEED_ID')) {
        $message = new Message();
        $message-&gt;setTo($email);
        $message-&gt;setSubject("Import complete");
        $message-&gt;setHtmlBody('Data has been imported successfully');
        $message-&gt;send();
    }         
});
</code></pre>

<p>I've been scratching my furry head but can't think of a solution, is there any way to do this?</p>

<plugin-development><plugin-feedme><modules>
Sending an e-mail to current user in FeedMe hook
# Sending an e-mail to current user in FeedMe hook

(Asked by: username_0 on 2020-02-19)

I have made a custom module that allows a user to upload a CSV and import it using a FeedMe feed. This all works fine, however I want to send an e-mail to the user when the import has completed.
I have this so far, but realised it doesn't work because the event doesn't have access to the user session:
Event::on(Process::class, Process::EVENT_AFTER_PROCESS_FEED, function(FeedProcessEvent $event) {                
    $email = Craft::$app->getUser()->getIdentity()->email;
    if ($event->feed->id === getenv('USER_FEED_ID')) {
        $message = new Message();
        $message->setTo($email);
        $message->setSubject("Import complete");
        $message->setHtmlBody('Data has been imported successfully');
        $message->send();
    }         
});

I've been scratching my furry head but can't think of a solution, is there any way to do this?

**Tags:** plugin-development, plugin-feedme, modules


---

## 1 answers

### Answer by username_1 on 2020-02-19. Score: 2 | Accepted answer

As long as you have control of the CSV on upload, you could change its name to `filename_test@test.test.csv` (or some other properly escaped filename with the current user's email address in it). Then get the filename from the feed (must be in there somewhere) and extract the email address.

Bit of a workaround, but if it works, it works.

> **Comments:**
> **username_0**: This is very creative I like it! However there may be times that another user selects a pre-uploaded CSV from another user so I'm not sure this will work for me. I will sit on it a little bit, but if it turns out this is the only way (which it seems it may be) I will give you that green tick!  

---

