The correlation between mechanical stress and magnetic properties of ultrathin films