I want to send test mail using Invoke Code. But it doesnt work. Why? My codes are below. I am using C#.
MailMessage mail = new MailMessage();
mail.From = new MailAddress(“testfrom@gmail.com”);
mail.Subject = “This is subject”;
mail.Body = “This is test mail body”;
mail.Priority= MailPriority.High;
string to="testto@gmail.com";
mail.To.Add(to);
SmtpClient smtp = new SmtpClient();
smtp.Host = “smtp.gmail.com”;
smtp.Port =587;
smtp.EnableSsl = true;
System.Net.NetworkCredential credential=new System.Net.NetworkCredential();
credential.UserName=mail.From.Address;
credential.Password=“this is password”;
smtp.Send(mail);
I have a problem. This is “Invoke code: Exception has been thrown by the target of an invocation.”.
Can you help me ?