.exe not working on Windows Server 2008 R2 Enterprise

77 Views Asked by At

I've been having some problems for the last 5 days with and .exe that I've made in Visual Studio Code (last version) on my PC with Windows 10. The issue is that the file isn't working in the server where I put it which has a Windows Server 2008 R2 Enterprise version. I've tried doing it using Python, VB and C# and none of the cases work. I leave the code in C# next:

using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Mail;

namespace EmailSender
{
    class Program
    {
        static void Main(string[] args)
        {
            // Datos de autenticación del correo electrónico
            string smtpServer = "smtp.office365.com";
            int smtpPort = 587;
            string smtpUsername = "[email protected]";
            string smtpPassword = "example";

            string rutaCarpeta = "C:/Example";

            string[] archivosExcel = Directory.GetFiles(rutaCarpeta, "*.xls")
                .OrderByDescending(f => new FileInfo(f).CreationTime)
                .Take(4)
                .ToArray();

            MailMessage correo = new MailMessage();
            correo.From = new MailAddress("[email protected]");
            correo.Subject = "Example subject";
            correo.To.Add("[email protected]");
            correo.To.Add("[email protected]");
            correo.Body = "Example body.";

            foreach (string archivo in archivosExcel)
            {
                correo.Attachments.Add(new Attachment(archivo));
            }

            SmtpClient smtpClient = new SmtpClient(smtpServer, smtpPort);
            smtpClient.EnableSsl = true;
            smtpClient.Credentials = new NetworkCredential(smtpUsername, smtpPassword);

            smtpClient.Send(correo);

            Console.WriteLine("Example writeline.");
        }
    }
}

The purpose of the .exe is to take 4 Excel files from a default folder and send them to some default emails. I've tried different languages, some compatibility configurations, different e-mail providers...

0

There are 0 best solutions below