Error while sending email with C# console app

  • Thread starter Thread starter Yerkhan
  • Start date Start date
Y

Yerkhan

Guest
Hi everyone.

I wanted to send automatic email with C# console app. Here is my code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
using System.Net;

namespace test_email
{
class Program
{
static void Main(string[] args)
{
SmtpClient client = new SmtpClient("smtp.gmail.com", 465);
client.EnableSsl = true;
MailAddress from = new MailAddress("[address_from]@gmail.com");
MailAddress to = new MailAddress("[address_to]@gmail.com");
MailMessage message = new MailMessage(from, to);
message.Body = "This is a test e-mail message sent using gmail as a relay server ";
message.Subject = "Gmail test email";
NetworkCredential myCreds = new NetworkCredential("[address_from]@gmail.com", "[pass]");
client.Credentials = myCreds;


try
{
client.Send(message);
}

catch (Exception ex)
{
Console.WriteLine("Exception is:" + ex.ToString());
}

Console.WriteLine("Goodbye.");
}
}
}



However, when I execute this code, I get error "Application exited with code 0 (0x0). How it can be fixed?

Regards,

Yerkhan

Continue reading...
 
Back
Top