<p>I need to attach a file with mailx but at the moment I am not having success.</p>

<p><strong>Here's my code:</strong></p>

<pre><code>subject="Something happened"
to="somebody@somewhere.com"
body="Attachment Test"
attachment=/path/to/somefile.csv

uuencode $attachment | mailx -s "$subject" "$to" &lt;&lt; EOF

The message is ready to be sent with the following file or link attachments:

somefile.csv

Note: To protect against computer viruses, e-mail programs may prevent
sending or receiving certain types of file attachments.  Check your
e-mail security settings to determine how attachments are handled.

EOF
</code></pre>

<p>Any feedback would be highly appreciated.</p>

<hr>

<p><strong>Update</strong>
I have added the attachment var to avoid having to use the path every time.</p>

Well, here are the first few problems you've got.
You appear to be assuming that a mail client is going to handle uuencoded attachment without any headers.  That won't happen.
You're misusing I/O redirection:  uuencode's output and the here-document are both being fed to mailx, which can't happen.
You're misusing uuencode:  if one path is given, it's just a name to give the decoded file, not an input file name.  Giving the file twice will assign the same name to the decoded file as that which was read.  The -m flag forces base64 encode.  But this still isn't going to provide attachment headers for mailx.
You're way better getting a copy of mpack, which will do what you want.
If you must do it, you could do something like this:
```
```
cat <<EOF | ( cat -; uuencode -m /path/to/somefile.csv /path/to/somefile.csv; ) | mailx -s "$subject" "$to" 
place your message from the here block in your example here
EOF
```
```
There are lots of other possibilities... but this one still has the here document
as in your example and was easy off the top of my head, and there's no temp file involved.