In this work, we present the program MAELAS to calculate magnetocrystalline anisotropy energy, anisotropic magnetostrictive coefficients and magnetoelastic constants in an automated way by Density Functional Theory calculations. The program is based on the length optimization of the unit cell proposed by Wu and Freeman to calculate the magnetostrictive coefficients for cubic crystals. In addition to cubic crystals, this method is also implemented and generalized for other types of crystals that may be of interest in the study of magnetostrictive materials. As a benchmark, some tests are shown for well-known magnetic materials.