# Cannot attach multiple files to an email

**URL:** <https://forum.ansible.com/t/cannot-attach-multiple-files-to-an-email/28560>\
**Category:** Ansible Project\
**Created:** [September 12, 2018, 2:54pm UTC](https://forum.ansible.com/t/cannot-attach-multiple-files-to-an-email/28560 "2018-09-12T14:54:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthieu\_Nantern](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@Matthieu\_Nantern](https://forum.ansible.com/u/Matthieu_Nantern)\
**Post date:** [September 12, 2018, 2:54pm UTC](https://forum.ansible.com/t/cannot-attach-multiple-files-to-an-email/28560/1 "2018-09-12T14:54:57Z")

</div>

Hi All !

I’m trying to attach multiple file to an email by using the [mail module](https://docs.ansible.com/ansible/2.4/mail_module.html) but it’s not working at all because I have parameters in my files’ name:

```auto
- name: send an email
  mail:
    host: email-smtp.eu-west-1.amazonaws.com
    port: 587
    username: xxx
    password: xxx
    from: xxx
    to: "{{ item.firstname }} {{ item.lastname }} <{{ item.email }}>"
    subject: configuration files
    body: "{{ lookup('template', 'email_body.j2') }}"
    secure: starttls
    attach: "/mnt/data/users_config/{{ item.firstname }}_{{ item.lastname }}.txt /mnt/data/users_config/{{ item.firstname }}_{{ item.lastname }}.pdf"
  loop: "{{ users }}"

I tried to add quotes almost everywhere but either it tries to load a single file (not splitting by space) resulting in a [Errno 2] No such file or directory or it ends up with an invalid yaml if I don't have the required quotes.

Any idea ?

Thank you !

```

---

<div class="post-metadata">

**Author:** ![Matthieu\_Nantern](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@Matthieu\_Nantern](https://forum.ansible.com/u/Matthieu_Nantern)\
**Post date:** [September 13, 2018, 6:42am UTC](https://forum.ansible.com/t/cannot-attach-multiple-files-to-an-email/28560/2 "2018-09-13T06:42:54Z")

</div>

Ok, I found my mistake !

I was reading the documentation for [Ansible v2.3](https://docs.ansible.com/ansible/2.3/mail_module.html) which states that attach is:

> A space-separated list of pathnames of files to attach to the message.

And I’m using Ansible v2.5 where attach is a classic list…

Using a list is working well.

Sorry for the noise
