Only a few things stood out to me about the message. The first of which is how you are populating
msg.Body
. As
Richard pointed out, you are actually overwriting when you add onto it instead of appending to it.
The preferred way to build up a string is to use the appropriately named
StringBuilder
class. Combining this with the
string.Format
method can give us a a nice multi-lined message with the keys and values
StringBuilder sb = new StringBuilder();
sb.AppendLine(string.Format("Name: {0}", name));
sb.AppendLine(string.Format("Contact No: {0}", contact));
sb.AppendLine(string.Format("Email: {0}", email));
sb.AppendLine(string.Format("City: {0}", city));
sb.AppendLine(string.Format("Message: {0}", message));
msg.Body = sb.ToString();
The other item is that you are using GMail as your email server. Google uses extra security measures to protect your account and it adds additional challenges to programmatic access- namely that their accounts cannot be accessed by most POP & SMTP (email) clients; which they refer to as
Less Secure Apps. You have a few options on what you can do, outlined in the referenced article.
References:
Microsoft Docs > StringBuilder Class[
^]
Microsoft Docs > String.Format Method[
^]
Google Accounts => Less secure apps & your Google Account[
^]