我在C#中創建了一個郵件發送器,但是程序在運行時會出錯。使用C發送郵件時出錯#
這是我的代碼:
MailMessage mail=new MailMessage("[email protected]","[email protected]","subject","this is a test");
SmtpClient smtp =new SmtpClient("smtp.gmail.com");
smtp.Port=587;
smtp.Credentials= new System.Net.NetworkCredential("username","pass");
smtp.Send(mail);
,這是錯誤:
System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. 79sm6578238wrc.34 - gsmtp
嘗試設置['.EnableSsl = TRUE;'](https://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.enablessl(V = vs.110) .aspx) – freefaller