attach file to message only if it is a valid file