Python script: como enviar email con archivo de texto adjunto

17 December, 2010

This week I created a Python script to:

  1. Read the content folder (path) looking for a file name pattern.
  2. Send by email files with the same pattern.
  3. Delete the files sent if required

To meet this objective I have created the program in the file send-attachment.py and the configuration variables in conf.py. By changing the values ​​in conf.py We can send the file containing the desired email addresses (to_addr) pattern (pattern) that We need. Failure to find any file with the pattern entered, the program sends an email to the address (alert) indicated to warn of the problem.
Sending email is done through an authenticated account (from_addr) on the same server SMTP (EMAIL_SERVER). That is why I recommend running the script with secure configuration file with read-only permissions for the user running: chmod 600 conf.py.

Next the files:

Greetings!

    Tags: , ,

    2 Comments

    1. juan carlos says:

      Me da un error en esta linea,
      for filename0 in filenames:

      • Carles says:

        Hola Juan Carlos,

        Esta entrada es del 2010 y en esa época no tenia los recursos que tengo ahora. He actualizado la entrada para solucionar este problema.

        Puedes encontrar el código encima de estas lineas y en mi Gist:
        Gist

        Saludos,
        c.

    Leave a Comment