我试图将我的163封电子邮件中的电子邮件发送到我的gmail,但是我收到了错误:
IOException: Connection closed
System.Net.Mail.SmtpClient.Read ()
System.Net.Mail.SmtpClient.SendCore (System.Net.Mail.MailMessage message)
System.Net.Mail.SmtpClient.SendInternal (System.Net.Mail.MailMessage message)
System.Net.Mail.SmtpClient.Send (System.Net.Mail.MailMessage message)
Rethrow as SmtpException: Message could not be sent.
System.Net.Mail.SmtpClient.Send (System.Net.Mail.MailMessage message)
sendM.Main () (at Assets/sendM.cs:27)I have
我不知道为什么会这样。我的代码如下所示:
public class mono : MonoBehaviour {
public string sender = "email@163.com";
public string receiver = "email@gmail.com";
public string smtpPassword = "password";
public string smtpHost = "smtp.163.com";
// Use this for initialization
public void Start() {
using (var mail = new MailMessage {
From = new MailAddress(sender),
Subject = "test subject",
Body = "Hello there!"
}) {
mail.To.Add(receiver);
var smtpServer = new SmtpClient(smtpHost) {
Port = 25,
Credentials = (ICredentialsByHost)new NetworkCredential(sender, smtpPassword)
};
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
smtpServer.Send(mail);
}
// }