Your code causes an issue because the initialization of MailMessage and its properties occurs directly within the class scope, which is not allowed. Instead, this should be done within a method, like Main() or another function. Class-level statements in C# can only declare fields and methods.