我試圖用C#中的Windows應用程序發送郵件。我的代碼如下,並嘗試,但它不工作使用gmail發送郵件smtp - 無法連接遠程服務器
它給以下錯誤:
Unable to connect the remove server
代碼:
MailAddress sendd = new MailAddress("[email protected]","Sethu",Encoding.UTF8);
MailAddress receivee = new MailAddress("[email protected]");
MailMessage mail = new MailMessage(sendd, receivee);
SmtpClient client = new SmtpClient();
client.Port = 587;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("[email protected]", "yyyyyyy");
mail.Subject = "this is a test email.";
mail.Body = "this is my test email body";
client.Send(mail);
任何幫助找出我做了什麼錯?
檢查這個的NetworkCredential(「[email protected]」,「 YYYYYYY「);電子郵件,你有收到電子郵件谷歌或雅虎允許訪問發送電子郵件到其他 –
它似乎你沒有權利發送郵件從這個憑據 –
在你的代碼中添加'EnableSsl = true'。 –