West Ham suffered their first defeat ahead of the new season as they lost 4-1 to Mainz at the Stadion am Bruchweg.