|Two things. ASP.NET code always executes on the server, never the client. That code will never be shown as part of "a page".
The first two attempts you show as "does not work" are because you're making assumptions about what those
smtpSection.Network.Password properties are returning. I would be willing to bet they don't return anything, so you're creating a NetworkCredential with blank username and password.
How do you tell? One word: debugger. Set a breakpoint on the line that creates the NetworkCredential and examine the values of UserName and Password. Chances are good those values are not what you think they are.