• Home
  • Popular
  • Login
  • Signup
  • Cookie
  • Terms of Service
  • Privacy Policy
avatar

Posted by Mark DS


28 Nov, 2024

Updated at 12 Dec, 2024

Why is my C# SMTP email code failing in Visual Studio Code?

I have a suspicion that the problem I am having has something to do with Visual Studio Code rather than with the C# code itself. I have recently configured my Visual Studio Code IDE to compile and build a C# (Command Line Console App) project and solution. But the moment I add meaningful code, it fales to properly recognize simple classes. Here is the simple test code I am trying:

``using System;
using System.Net;
using System.Net.Mail;
using System.Net.WebSockets;

namespace SendEmailWIthGoogleSMTP
{
class Program
{
string fromMail ="[email protected]";
string password ="REDACTED";

    MailMessage message = new MailMessage();
    message.From = new MailAddress(fromMail);
    message.Subject = "Test Subjecting";
    message.To.Add(new MailAddress([email protected]);
    message.Body ="This is a test";
    message.IsBodyHtml= false;

}

}

But here is the problem. It complains that 'message' is not defined albeit it does not complain after I define it. I know that sounds confusing, so here is the screen shot.

02_email