That is impossible! No such technology has yet been introduced that can send emails offline (unless we are talking about storing the email in
outbox). So, the actual thing happens when you are online, exception is raised. There are a lot of problems that can happen when you are working with networks. Network, authentication, SSL or other protocol or proxy based problems occur.
Your code looks fair to be executed, the only problem occurs if your authentication is not OK. The problem would cause your application to show you an error message that is returned from the Google servers telling you that you cannot send the email, using the credentials that you have provided them with.
Also, since you have not shown the error message, I would assume that the only problem is the username/password
or your account is a very new one and Google doesn't allow SMTP settings right now.
You need to check that in your settings panel and then allow SMTP or other settings; I had the similar problem 2 months ago with my new account.
Also, the code that you are using is not even of ASP.NET framework, that is native .NET framework's
System.Net.Mail
namespace being used. For that, please read this article of mine about
Sending emails over .NET framework, and general problems – using C# code[
^]. The article would discuss the possible problems while sending the emails, and a solution to solve them.