[Solved] How to send mail in c# instantly or at least perform it in background [closed]


        Task sendEmail = new Task(() =>
        {
            //create the mail message
            MailMessage mail = new MailMessage();

            //set the addresses
            mail.From = new MailAddress("[email protected]");
            mail.To.Add("[email protected]");

            //set the content
            mail.Subject = "This is an email";
            mail.Body = "this is a sample body";

            //send the message
            SmtpClient smtp = new SmtpClient();
            smtp.Port = 465;
            smtp.UseDefaultCredentials = true;

            smtp.Host = "smtp.gmail.com";

            smtp.EnableSsl = true;
            smtp.Credentials = new NetworkCredential("[email protected]", "YourPassword");  

            smtp.Send(mail);
        });

        sendEmail.Start();

solved How to send mail in c# instantly or at least perform it in background [closed]