3 回答

TA貢獻1865條經驗 獲得超7個贊
確保SmtpClient.Credentials 在致電后設置SmtpClient.UseDefaultCredentials = false。
該順序很重要,因為設置SmtpClient.UseDefaultCredentials = false將重置SmtpClient.Credentials為空。

TA貢獻1712條經驗 獲得超3個贊
要通過TLS / SSL發送消息,您需要將SmtpClient類的Ssl設置為true。
string to = "[email protected]";
string from = "[email protected]";
MailMessage message = new MailMessage(from, to);
message.Subject = "Using the new SMTP client.";
message.Body = @"Using this new feature, you can send an e-mail message from an application very easily.";
SmtpClient client = new SmtpClient(server);
// Credentials are necessary if the server requires the client
// to authenticate before it will send e-mail on the client's behalf.
client.UseDefaultCredentials = true;
client.EnableSsl = true;
client.Send(message);
- 3 回答
- 0 關注
- 759 瀏覽
添加回答
舉報