I have the following code that causes 'The SMTP host was not specified.' Any ideas why this happen? Many thanks
var mailMessage = new System.Net.Mail.MailMessage();
mailMessage.To.Add(new MailAddress("myemail@hotmail.co.uk"));
mailMessage.From = new MailAddress("atest@test.com");
mailMessage.Subject = "my test subject";
mailMessage.Body = "my test body";
mailMessage.IsBodyHtml = true;
var smtpClient = new SmtpClient { EnableSsl = true };
object userState = mailMessage;
smtpClient.Send(mailMessage);
I've tried the following now and it still fails
var client = new SmtpClient("smtp.gmail.com", 587)
{
Credentials = new NetworkCredential("me@gmail.com", "password"),
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false
};
var mail = new MailMessage("test@example.com", "me@gmail.com", "hello", "there");
mail.Body = "Hello";
mail.Subject = "hi";
client.Send(mail);