Để gửi thư qua TLS/SSL, bạn cần đặt Ssl của lớp SmtpClient thành 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);
Nguồn
2017-11-01 09:15:48
tên người dùng và mật khẩu đến từ đâu? và mail.mydomain.com là gì? là tên DNS của anh ta? – Shyju
là địa chỉ email và mật khẩu của bạn, mail.mydomain.com là máy chủ SMTP của bạn (ví dụ: smtp.gmail.com). – Arief
Bạn nên bọc đối tượng MailMessage trong một câu lệnh sử dụng (hoặc gọi Dispose vào nó sau khi bạn đã hoàn thành), phải không? – Ben